posted 12 years ago
Hi All,
I have the below requirement in my project. The project uses dynamic sql in its queries in the following way.
sqlQuery = sqlQuery + " AND GROUP IN ("+ userRole.toString().trim() + ") ";
userRole is StringBuffer whose value would be 'admin','inq'
Now the query hard codes the value, i want the value to be set at run time using PreparedStatement.
I tried modifiying the above query as below.
StringBuffer userRole = new StringBuffer(" ");
userRole.append(" ' ");
userRole.append("admin");
userRole.append(" ', ");
userRole.append(" ' ");
userRole.append("inq");
userRole.append(" ' ");
sqlQuery = sqlQuery + " AND GROUP IN ( ? );
stmt = conn.prepareStatement(sqlQuery);
stmt.setString(1,userRole.toString().trim());
But the problem here is while runtime, the below value is considered as a "single String" instead of two different strings due to which my query is failing.
'admin','inq'
Can someone help me out on this? I need the value to be two different strings when i am setting it dynamically.