try
        {
        Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
        Connection conn = null ;
        PreparedStatement pstmt = null ;
        ResultSet rs = null;
        conn = DriverManager.getConnection("jdbc:microsoft:sqlserver:/"+"/localhost:1433; DatabaseName=Northwind", "sa", "1234");
        String sqlstr = "select * from Categories";
        pstmt = conn.prepareStatement(sqlstr);   //调试的时候, 这里出错了。
        rs = pstmt.executeQuery();  
            new FrameMain().setVisible(true);
            this.dispose();
        rs.close();
        pstmt.close();
        conn.close();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            this.dispose();
        }
1.SQLSERVER已经安装了SP4补丁
2.我用的NETBEANS, 貌似都附带了驱动的那三个JAR包了。
3.出错的提示是:[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 'Categories' 无效。
可是, 我用的是SQL附带的那个NORTHWIND数据库, Categories数据表, 账号密码都应该没错的了。
不知道哪里错了, 求救大大。

解决方案 »

  1.   

    3.出错的提示是:[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 'Categories' 无效。 对不起,刚看到了。 请试试在数据库下直接运行那条语句,看看是不是出错? 如果出错,说明问题不在那段程序上。 我初步怀疑是数据库用户访问权限有问题。
      

  2.   

    use Northwind
    select * from Categories
    在查询分析器, 这样OK
      

  3.   

    在程序中改成[select * from Northwind.Categories]试试
      

  4.   

    米有这个Categories对象,这就说明了你所选择的数据库中没有这张表
      

  5.   

     try
            {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            Connection conn = null ;
            Statement pstmt = null ;
            ResultSet rs = null;        
            conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://" + "localhost" + ":" + "1433" +
                                                 ";databaseName=" + "dbJavaMIS" + ";selectMethod=" + "cursor" +";" , "sa", "1234");
            String text1 = jtfName.getText();
            String text2 = jtfPassword.getText();
            String sqlstr = "select * from T_User where [Name]='" + text1 + "' and [Password]='" + text2 + "'";
            pstmt = conn.createStatement();
            rs = pstmt.executeQuery(sqlstr);
            rs.last();               //这里提示出错
            int count = rs.getRow(); //存放记录的条数
            
            if(count != 0)             
            {  
                new FrameMain().setVisible(true);
                this.dispose();
                rs.close();
                pstmt.close();
                conn.close();
             }
            else
            {
                //输出账号密码错误!
                jLabel3.setText("无此账号密码!");
            }
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
                System.out.println("Error Trace in getConnection() : " + ex.getMessage());
                this.dispose();
            }       
    今天我上网找了很久, 把代码这样改了, 就能连接了。
    不过, rs.last();提示出错。 [Microsoft][SQLServer 2000 Driver for JDBC]Unsupported method: ResultSet.last
    这个应该怎样搞呢?
      

  6.   

            try
            {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            Connection conn = null ;
            Statement pstmt = null ;
            ResultSet rs = null;        
            conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://" + "localhost" + ":" + "1433" +
                                                 ";databaseName=" + "dbJavaMIS" + ";selectMethod=" + "cursor" +";" , "sa", "1234");
            String text1 = jtfName.getText();
            String text2 = jtfPassword.getText();
            String sqlstr = "select * from T_User where [Name]='" + text1 + "' and [Password]='" + text2 + "'";
            pstmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            rs = pstmt.executeQuery(sqlstr);
            //存放记录的条数
            rs.last();
            int count = rs.getRow();   //last位置的ROWINDEX        
            if(count != 0)             
            {  
                new FrameMain().setVisible(true);
                this.dispose();
                rs.close();
                pstmt.close();
                conn.close();
             }
            else
            {
                //输出账号密码错误!
                jLabel3.setText("无此账号密码!");
            }
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
                System.out.println("Error Trace in getConnection() : " + ex.getMessage());
                this.dispose();
            }       
    我终于搞好了, 呵呵