import java.sql.*;
public class DBOperation {
public static void main (String[] args){
try{//需要捕獲異常的代碼
Class.forName("sun.jdbc.obdc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:DingBao","sa","woshishab");
System.out.println("Connection success!");
conn.close();
}catch(Exception e){
System.out.println("connection failure!");
}
}
結果一直輸出連接失敗!太糾結了!
用com.microsoft.sqlserver.jdbc.SQLServerDriver
參考 http://blog.csdn.net/keenweiwei/article/details/7332261