error: syntax error from if clause
error: syntax error from if clause
String jk = "where nam='" + txt1.getText() + "'";
String ik = "and password='" + txt2.getPassword() + " ' ";
String sql;
sql = "SELECT * FROM Table1" + jk + ik;
rs = stmt.executeQuery(sql);
错误发生在 from 子句中的语法错误。
当您将 jk 和 ik 与 sql 组合时,table 名称和 where 子句之间没有 space。这就是你收到错误的原因。那里有规格
String jk =" where nam='"+txt1.getText()+"'";
String ik =" and password='"+txt2.getPassword()+" ' "; String sql;
sql = "SELECT * FROM Table1" +jk+ik;
rs = stmt.executeQuery(sql);
jk
和 ik
之间必须有一个空格
sql = "SELECT * FROM Table1" +jk+" "+ik;
但是最好还是了解准备好的语句。
尝试以下操作:
String jk =" where nam='"+txt1.getText()+"'"; //note the space before where
String ik =" and password='"+txt2.getPassword()+" ' //and space before and
String sql;
sql = "SELECT * FROM Table1" +jk+ik;
rs = stmt.executeQuery(sql);
最初您的查询看起来如下
SELECT * FROM Table1where nam='xyz'and password='xyz';
空格后
SELECT * FROM Table1 where nam='xyz' and password='xyz';
试试这个:
String jk =" where nam='"+txt1.getText()+"'";
String ik =" and password='"+txt2.getPassword()+" ' ";
String sql;
sql = "SELECT * FROM Table1" +jk+ik;
rs = stmt.executeQuery(sql);
您忘记在 "where" 和 "and" 之间添加空格
我也觉得 table 列
中的名字是 nam
在 from
和 where
子句之间添加空格。
String jk ="where nam='"+txt1.getText()+"'";
String ik ="and password='"+txt2.getPassword()+" ' "; String sql;
sql = "SELECT * FROM Table1" + " " + jk + " " + ik; rs = stmt.executeQuery(sql);
为了避免将来出现此类错误,我可以推荐 PreparedStatement
。 Here 是 Oracle 教程。
String stmnt = "SELECT * FROM Table1 WHERE nam=? and password=?;";
PreparedStatement pstmt = con.prepareStatement(stmnt);
pstmt.setString(1, txt1.getText());
pstmt.setString(2, txt2.getText());
ResultSet rs = pstmt.executeQuery();
String jk =" where nam='"+txt1.getText()+"' ";
String ik ="and password='"+txt2.getPassword()+"'";
String sql = "SELECT * FROM Table1" +jk+ik;
rs = stmt.executeQuery(sql);
这应该可以正常工作..!
干杯快乐编码.. :)
String jk = "where nam='" + txt1.getText() + "'";
String ik = "and password='" + txt2.getPassword() + " ' ";
String sql;
sql = "SELECT * FROM Table1" + jk + ik;
rs = stmt.executeQuery(sql);
错误发生在 from 子句中的语法错误。
当您将 jk 和 ik 与 sql 组合时,table 名称和 where 子句之间没有 space。这就是你收到错误的原因。那里有规格
String jk =" where nam='"+txt1.getText()+"'";
String ik =" and password='"+txt2.getPassword()+" ' "; String sql;
sql = "SELECT * FROM Table1" +jk+ik;
rs = stmt.executeQuery(sql);
jk
和 ik
sql = "SELECT * FROM Table1" +jk+" "+ik;
但是最好还是了解准备好的语句。
尝试以下操作:
String jk =" where nam='"+txt1.getText()+"'"; //note the space before where
String ik =" and password='"+txt2.getPassword()+" ' //and space before and
String sql;
sql = "SELECT * FROM Table1" +jk+ik;
rs = stmt.executeQuery(sql);
最初您的查询看起来如下
SELECT * FROM Table1where nam='xyz'and password='xyz';
空格后
SELECT * FROM Table1 where nam='xyz' and password='xyz';
试试这个:
String jk =" where nam='"+txt1.getText()+"'";
String ik =" and password='"+txt2.getPassword()+" ' ";
String sql;
sql = "SELECT * FROM Table1" +jk+ik;
rs = stmt.executeQuery(sql);
您忘记在 "where" 和 "and" 之间添加空格 我也觉得 table 列
中的名字是 nam在 from
和 where
子句之间添加空格。
String jk ="where nam='"+txt1.getText()+"'";
String ik ="and password='"+txt2.getPassword()+" ' "; String sql;
sql = "SELECT * FROM Table1" + " " + jk + " " + ik; rs = stmt.executeQuery(sql);
为了避免将来出现此类错误,我可以推荐 PreparedStatement
。 Here 是 Oracle 教程。
String stmnt = "SELECT * FROM Table1 WHERE nam=? and password=?;";
PreparedStatement pstmt = con.prepareStatement(stmnt);
pstmt.setString(1, txt1.getText());
pstmt.setString(2, txt2.getText());
ResultSet rs = pstmt.executeQuery();
String jk =" where nam='"+txt1.getText()+"' ";
String ik ="and password='"+txt2.getPassword()+"'";
String sql = "SELECT * FROM Table1" +jk+ik;
rs = stmt.executeQuery(sql);
这应该可以正常工作..! 干杯快乐编码.. :)