|
代码如下:
public class dbcon {
private static String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
private static String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=JXGL,sa,sa";
private Connection conn;
private Statement stmt;
public Connection getConnection(){
try{
Class.forName(driver);
conn=DriverManager.getConnection(url);
return conn;
}catch(ClassNotFoundException e){
JOptionPane.showMessageDialog(null,e.getMessage());
}catch(SQLException e){
JOptionPane.showMessageDialog(null,e.getMessage());
}
return null;
}
public boolean check(String name,String password){
String sql="select * from login where sno='"+name+"'";
try{
JOptionPane.showMessageDialog(null,sql);
conn=getConnection();
stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
if(rs.next()){
if(rs.getString("password")==password)
return true;
}
stmt.close();
conn.close();
}catch(SQLException e){
JOptionPane.showMessageDialog(null,e.getMessage());
}
return false;
}
}
每次运行时都会提示:
[Microsoft][SQL SERVER 2000 DRIVER FOR JDBC]Error establishing socket
我不知道是什么问题,请各位高手帮帮我,谢谢! |
|