在java连接oracle时候java.sql.SQLException: 无效的列索引

if(evt.getSource().equals(btLogin)){

try{
datacon = StarConnection.getConnection();
String str = "select * from management where name='"+txtId.getText()+"' and password='"+txtPass.getText()+"'";

pstat = datacon.prepareStatement(str);
pstat.setString(1, txtId.getText());
pstat.setString(2,txtPass.getText());
rs = pstat.executeQuery();
if(rs.next()){
txtId.setText("");
txtPass.setText("");

JOptionPane.showMessageDialog(null,"登陆成功!");

this.setVisible(false);
}
else
{
JOptionPane.showMessageDialog(null,"用户名或密码有错误!");
}

}catch(Exception e){
e.printStackTrace();
}

}
}
}

String str = "select * from management where name=? and password=?";



String str = "select * from management where name='"+txtId.getText()+"' and password='"+txtPass.getText()+"'";

pstat = datacon.prepareStatement(str);
pstat.setString(1, txtId.getText());
pstat.setString(2,txtPass.getText());


这里冲突了

追问

改了 还是不行!您的意思是怎么改呢?

追答String str = "select * from management where name='"+txtId.getText()+"' and password='"+txtPass.getText()+"'";

这个改为

String str = "select * from management where name=? and password=?";

其他不动追问

不行 改了还是问题 控制台现实数据库已连接,但是跳转不了界面

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答