import java.sql.*; public class Test { public static void main(String [] args) throws SQLException { String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver"; String url="jdbc:sqlserver://localhost:1433;databaseName=test"; String userName="sa"; //"MVF7JLVWLQ934VP"; //String userPwd= "password"; try { Class.forName(driverName); System.out.println("加载驱动成功!"); }catch(Exception e){ e.printStackTrace(); System.out.println("加载驱动失败!"); } try{ Connection dbConn=DriverManager.getConnection(url,userName,userPwd); dbConn.clearWarnings(); System.out.println("连接数据库成功!"); Statement SqlStatement = dbConn.createStatement(); ResultSet SqlResult = SqlStatement.executeQuery("SELECT * FROM STUDENT"); while(SqlResult.next() == true) { System.out.println(SqlResult.getString(1) + "\t" + SqlResult.getString(2)+ "\t" + SqlResult.getString(3)); } }catch(Exception e) { e.printStackTrace(); System.out.print("SQL Server连接失败!"); } } }