java - problem in jdbc preparestatement -


I am getting the error while trying to use the following, why is this?

  ResultSet findByU name (string tagname, string field, string value) {pStmt = cn.prepareStatement ("SELECT * FROM" + tablename + "WHERE? =?"); PStmt.setString (1, field); PStmt.setString (2, value); Return (pStmt.executeQuery ()); }  

I also tried the following, but this also is not working

  ResultSet findByUsername (string tablename, string field, string value) { String sqlQueryString = "SELECT * to" + tablename + "WHERE" + region + "=?") PStmt = cn.prepareStatement (sqlQuery); PStmt.setString (1, value); Return (pStmt.executeQuery ()); }  

You have:

  pStmt = Cn .prepareStatement ("SELECT * FROM" + tablename + "WHERE? =?"); PStmt.setString (1, Tablename); PStmt.setString (2, field); PStmt.setString (3, value);  

Two ? , but trying to set three parameters.

In fact, you can not set things like table and column names, through the prepared statement parameter.

You will need to constantly write the names and do anything about the check exceptions.

(Errors are caused when asking questions about the code, good ideas to quote errors.)


Comments