难道因为我装的是XP+sqlserver个人版的问题?

解决方案 »

  1.   

    我使用的也是Xp,和Sql Server。
    我的连接,楼主参考一下:
    public class DBConnection {
        
        public static Connection getDBConnection(){
            Connection conn = null;        String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
            String url ="jdbc:microsoft:sqlserver://URL:1433;DatabaseName=DBName";        
            String user = "cuilichen";
            String pwd = "clc";        try {
                Class.forName(driver).newInstance();             
                conn = DriverManager.getConnection (url,user,pwd);
            } catch(Exception e) {
                System.out.println("DBConnection err: " + e.toString());            
                return null;
            }
            return conn; 
        }}
    很常见的程序。需要把那三个经典的包导入工程中。
      

  2.   

    早就导了,代码发出来,大家帮忙看看咯
    package test;import com.sun.rowset.*;
    import java.sql.*;
    import javax.sql.rowset.*;
    import javax.sql.rowset.*;public class RowSetTest
    {
    public static void main(String[] agrs)
    {
    new RowSetTest();
    }

    CachedRowSet crs;
    public RowSetTest()
    {
    try{
    //Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    Class.forName("org.gjt.mm.mysql.Driver");
    crs = new CachedRowSetImpl();
    crs.setUrl("jdbc:mysql:///test");
    //crs.setUrl("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test");
    //crs.setUsername("sa");
    crs.setUsername("root");
    crs.setPassword("");
    crs.setCommand("select * from table1");

    crs.setPageSize(2);
    crs.execute();

    while(crs.nextPage())
    {
    while(crs.next())
    {
    System.out.println(crs.getInt(1)+"\t"+crs.getString(2));
    }
    }
    }catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    }
    换了Mysql还是不行,报下面这个错
    Exception in thread "main" java.lang.AbstractMethodError: org.gjt.mm.mysql.jdbc2
    .DatabaseMetaData.locatorsUpdateCopy()Z
            at com.sun.rowset.CachedRowSetImpl.execute(CachedRowSetImpl.java:757)
            at com.sun.rowset.CachedRowSetImpl.execute(CachedRowSetImpl.java:1385)
            at test.RowSetTest.<init>(RowSetTest.java:29)
            at test.RowSetTest.main(RowSetTest.java:12)
    Press any key to continue...
      

  3.   

    (1)换驱动:net.sourceforge.jtds.jdbc.Driver
    (2)SQL Server 打 SP3
    (3)重启
    (4)保证你的电脑能连到数据库服务器