JAVA与 SQL server2008进行连接

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) + "	" + SqlResult.getString(2)+ "	" + SqlResult.getString(3));
    }
}catch(Exception e)
{
    e.printStackTrace();
    System.out.print("SQL Server连接失败!");
}        
}

}
原文地址:https://www.cnblogs.com/nigel-jw/p/3414802.html