0

I have a two table called student and book. student table having 3 column studentid,name,coursename; book table having 4 column student id,name ,coursename,bookname,

I am trying to create a query that will get student id from book table and comapare with student table and if id match with that table the value will get printed but I am getting an error "java.sql.SQLSyntaxErrorException: Unknown column '1' in 'where clause'"

  String abc=txt1.getText();
  String sql;
  sql = "select * from `student` where studentid = `"+abc+"`";

Can anyone see what I am doing wrong here?

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • You should be using a `PreparedStatement` and bind parameters. You also need to tell us what type `studentid` is (in the database). And your `String` looks really funky the way you've posted it. – Elliott Frisch Apr 17 '21 at 14:37
  • You're putting the value of `abc` in backticks, which makes it a column name, not a string. – Barmar Apr 17 '21 at 14:38

0 Answers0