import java.sql.*;
import javax.swing.*;
class ConnectServer{
static Connection con=null;
public static boolean conn(String url,String username,String password){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(Exception e){
e.printStackTrace();
return false;
}
try{
con=DriverManager.getConnection(url,username,password);
}
catch(SQLException e){
e.printStackTrace();
return false;
}
return true;
}
public static boolean close(){
try{
con.close();
con=null;
}
catch(SQLException e){
return false;
}
return true;
}
public static void main(String args[]){
if(conn("jdbc:microsoft:sqlserver://localhost:1433;DataBaseName==data","sa","")){
JOptionPane.showMessageDialog(null,"数据库连接成功");
close();
}
else
JOptionPane.showMessageDialog(null,"数据库连接失败");
}
}
我上网下载了msbase.jar,mssqlserver.jar和msutil.jar,并把这三个类包放到jdk\jre\lib\ext\目录下了,可是还是提示“数据库连接失败”!请问是什么问题啊??谢谢