When a query is executed by a Statement object, it works fine, but executing the same query by a PreparedStatement object throws an SQL Exception.
This request is working fine ...
String query = "SELECT A, B, C, D, LOBJ FROM TABLE WHERE LOBJ = 'sGMMEMDEML2'; Statement stmt = con.createStatement() ResultSet rs = stmt.executeQuery(query);
This query throws a sql exception (DB2 SQL error: SQLCODE = -302, SQLSTATE = 22001, SQLERRMC = null) ...
String query = "SELECT A, B, C, D, LOBJ FROM TABLE WHERE LOBJ = ?; PreparedStatement preStmt = con.prepareStatement(query); preStmt.setString(1, 'sGMMEMDEML2'); ResultSet rs = preStmt.executeQuery();
The LOBJ column in the TABLE view has a length of 10 char, but its specified value is in where, where the sentence may or may not be 10 char long due to some restriction in the application.
Can someone help me on how this can be accomplished with PreparedStatement.
Thanks in advance.
source share