rs.next()返回值总是false 数据表中有数据! 5
JButtonbtnNewButton=newJButton("登录");btnNewButton.addActionListener(newActionListener...
JButton btnNewButton = new JButton("登录");
btnNewButton.addActionListener(new ActionListener() {
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent e) {
String tname =textField.getText() ;
String tpass = new String(passwordField.getPassword());
if(tname.equals("") && tpass.equals("")){
JOptionPane.showMessageDialog(null, "密码或用户名缺失,请重新登陆","提示",JOptionPane.INFORMATION_MESSAGE);
Loginclass frame = new Loginclass();
frame.setVisible(true);}
else{
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String user = "scott";
String password = "123";
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
String sql = "Select * from user_21819 where uname='"+tname+"' and upwd='"+tpass+"'";
try {
conn = DriverManager.getConnection(url,user,password);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if(rs.equals(null)){
JOptionPane.showMessageDialog(null, "无密码或用户名,请重新登陆","提示",JOptionPane.INFORMATION_MESSAGE);
return;
}
else{
if(rs.next()){
if((rs.getString("uname").equals(tname))&&(rs.getString("upwd").equals(tpass))){
JOptionPane.showMessageDialog(null, "登陆成功","提示",JOptionPane.INFORMATION_MESSAGE);
user frame = new user();
frame.setVisible(true);
return;
}
else{JOptionPane.showMessageDialog(null, "用户名不存在,请重新登陆","提示",JOptionPane.INFORMATION_MESSAGE);
return;}
}
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
finally {
try {
if(rs!=null){
rs.close();
}
if(stmt!=null){
stmt.close();
}
if(conn!=null){
conn.close();
}
}catch (SQLException e1) {
e1.printStackTrace();
}
}
}
}
}
); 展开
btnNewButton.addActionListener(new ActionListener() {
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent e) {
String tname =textField.getText() ;
String tpass = new String(passwordField.getPassword());
if(tname.equals("") && tpass.equals("")){
JOptionPane.showMessageDialog(null, "密码或用户名缺失,请重新登陆","提示",JOptionPane.INFORMATION_MESSAGE);
Loginclass frame = new Loginclass();
frame.setVisible(true);}
else{
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String user = "scott";
String password = "123";
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
String sql = "Select * from user_21819 where uname='"+tname+"' and upwd='"+tpass+"'";
try {
conn = DriverManager.getConnection(url,user,password);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if(rs.equals(null)){
JOptionPane.showMessageDialog(null, "无密码或用户名,请重新登陆","提示",JOptionPane.INFORMATION_MESSAGE);
return;
}
else{
if(rs.next()){
if((rs.getString("uname").equals(tname))&&(rs.getString("upwd").equals(tpass))){
JOptionPane.showMessageDialog(null, "登陆成功","提示",JOptionPane.INFORMATION_MESSAGE);
user frame = new user();
frame.setVisible(true);
return;
}
else{JOptionPane.showMessageDialog(null, "用户名不存在,请重新登陆","提示",JOptionPane.INFORMATION_MESSAGE);
return;}
}
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
finally {
try {
if(rs!=null){
rs.close();
}
if(stmt!=null){
stmt.close();
}
if(conn!=null){
conn.close();
}
}catch (SQLException e1) {
e1.printStackTrace();
}
}
}
}
}
); 展开
1个回答
展开全部
你高茄们开咐缓发JAVA不是有一个设戚简察置断点的功能么?(这个我很久没有弄过那个东西了)。。 应该可以讲rs这个对象输出看是否为空,就可以看到你这条sql语句执行到底有没有问题。。
追问
弄过了 可是还是空值 我的表里不止一条数据 按道理应该返回ture 啊 可是还是悲剧
追答
先把t_name和t_pass输出出来看看,如果得到了值,请把这两个值带入你的sql语句中,然后在数据库中执行看有没有结果。。 如果能够查询出结果,那就是你后面一段出问题,如果没有结果,那就是你得到的参数有问题。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询