public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
if (source == b_sure) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("成功加载JDBC-ODBC驱动程序!");
}
catch (ClassNotFoundException ex) {
System.out.println("加载JDBC-ODBC驱动程序失败!");
System.out.println(ex.getMessage());
return;
}
try {
Connection connection = DriverManager.getConnection("jdbc:odbc:jxzlgl", "sa", "123456");
Statement st = connection.createStatement();
String query = "SELECT * FROM 用户表 WHERE 用户名='"+tf_id.getText()+"'";
ResultSet rs = st.executeQuery(query);
System.out.println(rs.getString("2"));
/*if (rs.next()) {
if (p_key.getText() != rs.getString(2)) {
JOptionPane.showMessageDialog(null, "密码错误!", "错误:", JOptionPane.ERROR_MESSAGE);
}
else {
JOptionPane.showMessageDialog(null, "登陆成功", "!", JOptionPane.WARNING_MESSAGE);
}
}
else {
JOptionPane.showMessageDialog(null, "用户不存在!", "错误:", JOptionPane.ERROR_MESSAGE);
}*/
rs.close();
st.close();
connection.close();
}
catch(SQLException ec) {
System.out.println("查询数据库失败!");
System.out.println("SQLException:"+ec.getMessage());
}
}
}