import java.sql.*;
public class ConnDB {
public ConnDB() {
}
public Connection getConnect(){
Connection con = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs","sa","");//pubs数据库,后面两个参数是用户名和密码
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
public static void main(String[] args) throws Exception {
System.out.println(new ConnDB().getConnect());
}
}
再去下个SQLserver驱动,有3个文件,加入环境变量就可以了 msbase.jar /mssqlserver.jar/ msutil.jar
附件限制大小,要不我就传上来了