How to use PreparedStatement on Oracle NoSql Java SDK?

208 Views Asked by At

I have a simple question about the PreparedStatement on Oracle NoSql Java SDK:

What is the issue with this code? What is the right query to bind the runtime param from PreparedStatement?

String sql = "SELECT * FROM property WHERE id= ?";
QueryRequest qr = new QueryRequest();
PrepareRequest prepareRequest = new PrepareRequest().setStatement(sql);
PrepareResult prepareResult = getHandler().prepare(prepareRequest);
PreparedStatement preparedStatement = prepareResult.getPreparedStatement();
preparedStatement.setVariable(1, new StringValue("1971ba5d8babbd167448fba5f70584f1"));
1

There are 1 best solutions below

0
Dario On

My understanding is that the "?" syntax is not yet supported.

You need to declare the query as follows

String sql = "declare $id string; select * from property where id = $id";

and then set the variable using the name and not the position

preparedStatement.setVariable("$id", new StringValue("1971ba5d8babbd167448fba5f70584f1"));