java怎样连接 SQL Server 2005
展开全部
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ToSQL {
public static void main(String args[]){
new ToSQL();
}
public ToSQL(){
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=XXX","sa","XXXXXX");
System.out.println("数据库连接成功!!!");
} catch (Exception e) {
System.out.println("数据库连接失败!!!");
e.printStackTrace();
}
}
}
import java.sql.DriverManager;
import java.sql.SQLException;
public class ToSQL {
public static void main(String args[]){
new ToSQL();
}
public ToSQL(){
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=XXX","sa","XXXXXX");
System.out.println("数据库连接成功!!!");
} catch (Exception e) {
System.out.println("数据库连接失败!!!");
e.printStackTrace();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询