Reputation: 127
I have a textbox. When the user enters the name in the textbox I want the details fetched from the table
String getTxt = text.getText();
ResultSet rs=st.executeQuery("SELECT * FROM authors_4 WHERE self_authors="+getTxt);
On executing this i'm getting exception
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
What is the solution to this. Need help
Upvotes: 0
Views: 48
Reputation: 159754
You're missing single quotes:
st.executeQuery("SELECT * FROM authors_4 WHERE self_authors='" + getTxt + "'");
Better use a PreparedStatement
to protect against SQL Injection attacks.
Upvotes: 3