以前还可以,现在就不行.气死我了。
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:8300;DatabaseName=xsgl","sa","")){
JOptionPane.showMessageDialog(null, "数据库连接成功");
close();
}
else
JOptionPane.showMessageDialog(null, "数据库连接失败");
}
}
错误提示: