Connection conn=null;
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//加载驱动
String url="jdbc:sqlserver://localhost:1433;DatabaseName=Eg";
conn=DriverManager.getConnection(url,"wwlei","asd123");//获取连接
System.out.println(conn);//检查连接十分正常
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
try{
conn.close();
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
}