Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

JDBC Result set from HANA procedure part 2 #34

Open
tbealby opened this issue Jun 28, 2016 · 0 comments
Open

JDBC Result set from HANA procedure part 2 #34

tbealby opened this issue Jun 28, 2016 · 0 comments

Comments

@tbealby
Copy link

tbealby commented Jun 28, 2016

This is a continuation of 'JDBC Result set from HANA procedure #33'

I have now (at last!) managed to get the result set back from my HANA procedure with the following code using a regular JDBC connection

String sql = "CALL "XX_SCHEMANAME".mySprocName(?,?,?,?)";
CallableStatement callableStatement = connection.prepareCall(sql);
callableStatement.setString(1, "val1");
callableStatement.setString(2, "val2");
callableStatement.setString(3, "val3");
callableStatement.setInt(4, 123);
boolean b = callableStatement.execute();
resultSet = callableStatement.getResultSet();


Please will you let me know whether vertx is using callable statements any where? I can't see that it does.

The following dirty hack of JdbcProcessor.doSelect gets me back the result set from the HANA procedure

private void doSelect( final Message message,
Connection connection,
TransactionalHandler transaction ) throws SQLException {
new BatchHandler( connection, message, transaction ) {
public JsonObject process() throws SQLException {
JsonObject reply = new JsonObject() ;
ArrayList<Map<String,Object>> result = new ArrayList<Map<String,Object>>() ;
// processing
while( ( resultSet != null || valueIterator.hasNext() ) &&
( batchSize == -1 || result.size() < batchSize ) ) {
LimitedMapListHandler handler = new LimitedMapListHandler( batchSize == -1 ? -1 : batchSize - result.size() ) ;
if( resultSet == null ) {
List params = valueIterator.next() ;
boolean callable = params.size() > 1;// <-----------Flag value is hacked here - needs passing from client properly.
if (callable) {
String sql = message.body().getString( "stmt" ) ;
statement = connection.prepareCall(sql);
int i = 1;
for (Object param: params) {
statement.setObject(i++, param);
}
boolean isResultSet = statement.execute();
if (isResultSet) {
resultSet = statement.getResultSet();
}
}
else {
statementFiller.fill( statement, params ) ;
resultSet = statement.executeQuery() ;
}
}
store( result, handler ) ;
}
reply.putArray( "result", JsonUtils.listOfMapsToJsonArray( result ) ) ;
return reply ;
}
}.handle( message ) ;
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant