package com.xujianyou;
import java.sql.*;
public class TestConnect {
public static void main(String []args) {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
String user = "sa";
String password = "da";
Connection con = DriverManager.getConnection(url, user, password);
Statement sta = con.createStatement();
int result = sta.executeUpdate();
if (result > 0) {
//证明成功插入啊.你就可以在这里写你想写的动作
}
else {
//插入失败!
}
} catch(Exception e){
e.printStackTrace();
}
}
}