jsp连接到SqlServer2000数据库的test代码
1个回答
展开全部
static String serverName = "localhost";
static String postNumber = "1433";
static String databaseName = "test";
static String userName = "sa";
static String password = "sa";
static String getUrl(){
String url = "jdbc:microsoft:sqlserver://" + serverName + ":"+ postNumber + ";datebaseName=" + databaseName;
return url;
}
static Connection getConnection(){
Connection con = null;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ClassNotFoundException ne){
System.out.println("加载失败");
}
try{
con = DriverManager.getConnection(getUrl(),userName, password);
if(con != null){
System.out.println("连接成功!");
}else{
System.out.println("连接失败!");
}
}catch(SQLException se){
System.out.println(se);
}
return con;
}
三个jar包你有吧?
static String postNumber = "1433";
static String databaseName = "test";
static String userName = "sa";
static String password = "sa";
static String getUrl(){
String url = "jdbc:microsoft:sqlserver://" + serverName + ":"+ postNumber + ";datebaseName=" + databaseName;
return url;
}
static Connection getConnection(){
Connection con = null;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ClassNotFoundException ne){
System.out.println("加载失败");
}
try{
con = DriverManager.getConnection(getUrl(),userName, password);
if(con != null){
System.out.println("连接成功!");
}else{
System.out.println("连接失败!");
}
}catch(SQLException se){
System.out.println(se);
}
return con;
}
三个jar包你有吧?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询