david20002062 david20002062 - 2 years ago 468
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();
table.setModel(DbUtils.resultSetToTableModel(rs));

} catch (SQLException e) {

e.printStackTrace();
}


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:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
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