62,623
社区成员
发帖
与我相关
我的任务
分享
public class bean {
Connection Con = null;
public bean() {
BuildConnection();
}
public void BuildConnection() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Con = DriverManager.getConnection("jdbc:odbc:xxy", "sa", "");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public Connection getConnection() {
if (Con == null)
BuildConnection();
return this.Con;
}
public void close() {
try {
Con.close();
Con = null;
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
public String checkd(String username, String password) {
String pass = null;
try {
Statement stm = Con.createStatement();
String sql = "select password from dl where name='"
+ username + "'";
ResultSet rs = stm.executeQuery(sql);
if (rs == null)
return ("请输入用户名!");
if (rs.next()) {
pass = rs.getString(2);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
if (pass.equals(password))
return ("登录成功!");
else
return ("密码错误!");
}
}