0

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You are using ' "+getTxt+" ' ` ", shouldnt it be ' "+getTxt+" ' "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.