Connection conn=null;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url ="jdbc:microsoft:sqlserver://192.168.24.181:1433;DatabaseName=LiNing";
String user="sa";
String password="123";
conn=DriverManager.getConnection(url,user,password);
out.println("取得一個數據庫連接");
out.print(conn.toString());
注:不同數據的url是不同的,所以說當改變數據庫的時候url應作出相應的改變,前邊對於不同的url我已經論述過了在這不必多講。