private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String sql="select * from account where Username and Password=(?,?)"; //I think here is some error but dont know what it is
try
{
stm=con.prepareStatement(sql);
stm.setString(1,jTextField1.getText());
stm.setString(2,jPasswordField1.getText());
rs=stm.executeQuery();
if(rs.next())
{
rs.close();
stm.close();
setVisible(false);
Loading ob =new Loading();
ob.setVisible(true);
}
else
{
JOptionPane.showMessageDialog(null,"Incorrect username and password");
}
}
catch(SQLException exp)
{
JOptionPane.showMessageDialog(null, exp);
}
finally
{
try
{
rs.close();
stm.close();
}
catch(SQLException exp)
{
exp.printStackTrace();
}
}
}
答案 0 :(得分:1)
String sql="select * from account where Username and Password=(?,?)";
嗯,我没有SQL专家,但我认为应该是:
String sql="select * from account where Username = ? and Password=?";
我希望你每次遇到一些问题时都打算提问。你不能猜到SQL语法是什么,所以你需要买一本书或找一个教程。
也许JDBC Database Access可以为您提供一些一般信息。
答案 1 :(得分:0)
你想要
WHERE username=? AND password=?
答案 2 :(得分:-2)
使用以下查询:
"select * from account where Username=? and Password=?;"
答案 3 :(得分:-3)
您应该使用简单的Statement而不是PreparedStatement,并在查询中放置用户并传递字段文本。
此示例代码可以帮助您
stmt = con.createStatement();
String sql = "select * from table where Username='"+user.getText()+"' AND Password='"+pass.getText()+"'";
res = stmt.executeQeury(sql);