david20002062 david20002062 - 5 years ago 842
SQL Question

Java MySQLSyntaxError

I'm building a program around a MySQL database using JDBC Driver.
I'm stuck at this point.

loginWindow lW = new loginWindow();
try {
PreparedStatement pst = connHandler.conn.prepareStatement("SELECT * FROM '" + lW.fieldUname.getText() + "''");

ResultSet rs = pst.executeQuery();

} catch (SQLException e) {


I have a connHandler class which is holding the connection method and the Connection (named: "conn") variable. I assume I have some problems with my query.

The error that I'm getting:

You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ''''' at line 1

I would really appreciate any help or advice.

Answer Source

use that

 "SELECT * FROM '" + lW.fieldUname.getText() + " ' "

you have two of " ' " that at the end

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download