在java连接oracle时候java.sql.SQLException: 无效的列索引
if(evt.getSource().equals(btLogin)){try{datacon=StarConnection.getConnection();String...
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();
}
}
}
} 展开
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();
}
}
}
} 展开
1个回答
2014-12-11
展开全部
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=?";其他不动
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询