对的,微软的驱动改过了。你的类写法有问题。请参考我写的代码。package jdsTutorial;
import java.sql.*;public class SQLT01 { public static void main(String[] args) { // Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost\\SQLEXPRESS;" +
"user=db51;password=mssql"; // Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null; try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl); // Create and execute an SQL statement that returns some data.
String SQL = "SELECT TOP 10 * FROM USR";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL); // Iterate through the data in the result set and display it.
while (rs.next()) {
System.out.println(rs.getString("PARTICIPANT") + " " + rs.getString("PDMUSRPASSWD"));
}
} // Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
}}
import java.sql.*;public class SQLT01 { public static void main(String[] args) { // Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost\\SQLEXPRESS;" +
"user=db51;password=mssql"; // Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null; try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl); // Create and execute an SQL statement that returns some data.
String SQL = "SELECT TOP 10 * FROM USR";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL); // Iterate through the data in the result set and display it.
while (rs.next()) {
System.out.println(rs.getString("PARTICIPANT") + " " + rs.getString("PDMUSRPASSWD"));
}
} // Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货