To work around this issue, load the 2005 version of the JDBC driver class first, as follows:Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); // 2005 version Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); // 2000 versionThis will ensure that the "jdbc:sqlserver://" URL prefix is handled by the 2005 version of the JDBC driver and the "jdbc:microsoft:sqlserver://" URL prefix is handled by the 2000 version of the JDBC driver.
Connection conn = DriverManager.getConnection(
"jdbc:sqlserver://localhost;DatabaseName=Stephen;SelectMethod=cursor", "sa", "sally");
我是这么写的,请问怎么错了!
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=Northwind", "sa", "");
}catch (Exception e) {
e.printStackTrace();
}
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Stephen,"sa", "sally");
jdbc:sqlserver://localhost;DatabaseName=Stephen;SelectMethod=cursor
这里错了,少了jdbc如下:
com.microsoft.jdbc.sqlserver.SQLServerDriver
jdbc:microsoft:sqlserver://
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"databaseName=AdventureWorks;user=MyUserName;password=1111;";
Connection con = DriverManager.getConnection(connectionUrl);
class first, as follows:Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); // 2005 version
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); // 2000 versionThis will ensure that the "jdbc:sqlserver://" URL prefix is handled
by the 2005 version of the JDBC driver and the "jdbc:microsoft:sqlserver://"
URL prefix is handled by the 2000 version of the JDBC driver.
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Northwind", "sa", "");
}catch (Exception e) {
e.printStackTrace();
}