it's not advisable to connect to database directly using applet. You should use a servlet as middleware

解决方案 »

  1.   

    I know that ,But I do not know how to use servlet ,because of being a newer of Java technology. would you like to help me again?
      

  2.   

    then you should read sth on Servlet. You may download the tutorial from sun.java.com.
    oh read a book such as "java servlet programming", 
    it's not possible to teach you everything here
    after that, i can show you how to communicate applet and servlet
      

  3.   

    打开某个数据库的连接public void openConnection()
        {
        theDataSource="jdbc:odbc:MyAccess";
        theUser="";
        thePassword="";
        try
        {
        Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
    theConnection=DriverManager.getConnection(theDataSource,theUser,thePassword);
            theStatus.setText("Status:OK");
        }
        catch (Exception e)
            {
            handleException(e);
            }
        }
    执行SQL命令public void execSQLCommand(String command)
    {
        try{
            theStatement=theConnection.createStatement();
            theResult=theStatement.executeQuery (command);
            theMetaData=theResult.getMetaData ();
            int columnCount=theMetaData.getColumnCount ();
            theVisits.setText("");
            while(theResult.next ())
            {
                for(int i =1;i<=columnCount;i++)
                {
                    String colValue=theResult.getString(i);
                    if(colValue==null)colValue="";
                    theVisits.append (colValue+";");
                }
                theVisits.append ("
    ");
            }
        }catch(Exception e)
        {
            handleException(e);
        }
    }
    其实我觉得跟jsp访问数据库没什么差别!
    而且还比较麻烦,显示的格式必须自己手写代码来完成。
      

  4.   

    oh,thanks!
    I will try it, and hope all of you continue to help me.
      

  5.   

    你可以用一个中间服务程序来完成,数据读写操作,applet来访问这个服务程序,这样就是三层结构:applet<-->中间服务程序<-->数据库.
    中间服务程序<-->数据库,之间的读写用上面那位仁兄(: zmrljl(javaone) (  ) 信誉:100 )讲的。
    applet<-->中间服务程序:用socket来实现。
    这样做有一定的好处,不过速度会慢。
      

  6.   

    Just a matter of communication between serlvet and applet.
    A lot of books and learning materials can be found.
      

  7.   

    我有点怀疑,上面的程序,据我所知Applet是运行在客户端的,客户端是不会有已经建好的数据源的,我认为上述程序在本机上测试可以通过,但在其他的机器上恐怕就找不到数据源了
      

  8.   

    servlet 中:
    数据库连接
    组合数据
    输出流applet 中:
    连接servlet 
    读出流