import java.sql.*;
public class T1{
public static void main(String []args)
{
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("成功加载SQL驱动程序");
}
catch(Exception e){
System.out.println("找不到SQL驱动程序");
}
try{
String a="sa";
String b="123456";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url="jdbc:sqlserver://localhost:1433;DatabaseName=kang";
Connection conn=DriverManager.getConnection(url,a,b);
if(conn!=null){
System.out.println("数据库连接成功");
}
}
catch(Exception e){
e.printStackTrace();
}
}
}
public class T1{
public static void main(String []args)
{
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("成功加载SQL驱动程序");
}
catch(Exception e){
System.out.println("找不到SQL驱动程序");
}
try{
String a="sa";
String b="123456";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url="jdbc:sqlserver://localhost:1433;DatabaseName=kang";
Connection conn=DriverManager.getConnection(url,a,b);
if(conn!=null){
System.out.println("数据库连接成功");
}
}
catch(Exception e){
e.printStackTrace();
}
}
}