本帖最后由 popoisApig 于 2010-02-06 15:04:32 编辑

解决方案 »

  1.   

            Connection conn = DriverManager.getConnection(url);
    这句不对,要三个参数,你只传了一个,虽然你把三个写一起变成一个了,但这样不行。
    分开写
      

  2.   

    API如下:
    getConnection
    public static Connection getConnection(String url)
                                    throws SQLExceptionAttempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers. Parameters:
    url - a database url of the form jdbc:subprotocol:subname 
    Returns:
    a connection to the URL 
    Throws: 
    SQLException - if a database access error occurs
      

  3.   

    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position.
      

  4.   

    控制台有没有打印出数据??
    你把while语句改成rs.next()试试
      

  5.   

    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position. 说明是你的JDBC连接数据库出了问题,和Swing没有关系了
    JDBC连接MSSQLserverClass.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
    String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
    //mydb为数据库
    String user="sa";
    String password="";
    Connection conn= DriverManager.getConnection(url,user,password); 
      

  6.   


    这样
    try {
                        Class.forName(drivername);
                        Connection conn = DriverManager.getConnection(url);
                        Statement stmt = conn.createStatement();
                        ResultSet rs = stmt.executeQuery(sql);        
                        rs.next();            
                        jta_data.setText(rs.getString(1)+"");
                        jta_data.setText(rs.getString(2)+"");
                        jta_data.setText(rs.getString(3)+"");
                        jta_data.setText(rs.getString(4)+"");
                    } catch (Exception e1) {
                        // TODO: handle exception
                        e1.printStackTrace();
                    }
      

  7.   


    控制台有数据输出,但是窗体中textarea内没有数据输出。
    截图如下
      

  8.   

    这是因为rs.next()在while循环中移到了数据集尾部 循环后jta_data.setText(rs.getString(1)+"")里就没数据可以取了 照我7楼的代码改应该就能输出第一条数据 要想全部输出还要再改
      

  9.   


    2 admin admin null
    4 ceshi test [email protected]
    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position.
    at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
    at com.microsoft.jdbc.base.BaseResultSet.validateCursorPosition(Unknown Source)
    at com.microsoft.jdbc.base.BaseResultSet.getString(Unknown Source)
    at exa1.db2$1.actionPerformed(db2.java:58)
      

  10.   

    try {
                        Class.forName(drivername);
                        Connection conn = DriverManager.getConnection(url);
                        Statement stmt = conn.createStatement();
                        ResultSet rs = stmt.executeQuery(sql);        
                        String text="";
                        while (rs.next()) {
                            text+=rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4)+"\n";
                        }
                        
                        jta_data.setText(text);
                      
                    } catch (Exception e1) {
                        // TODO: handle exception
                        e1.printStackTrace();
                    }