JavaApplication couldn't get ResultSet from Vertica

Hi there!

 

I'm using vertica-jdbc-7.1.2-0 (https://my.vertica.com/download/vertica/client-drivers/) and jdk 1.8.0_73 in my Java-app.

 

I'm trying to get ResultSet from my query and print it to the java-console.

 

If I use simple query like "select sysdate from dual" there is no problem to print it to the java-console.

But if I use hard query with few JOINs and WHEREs I get nothing in java-console (looks like ResultSet is null). 

 

My code for print ResultSet:

connection = getConnection();
Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery(sql);
ResultSetMetaData rsmd = resultSet.getMetaData();
int columnsNumber = rsmd.getColumnCount();

while (resultSet.next()) {
System.out.println("Make sure that ResultSet exists: " + resultSet.getString(1));

for (int i = 1; i <= columnsNumber; i++) {
if (i > 1) System.out.print(", ");
String columnValue = resultSet.getString(i);
System.out.print(columnValue + " " + rsmd.getColumnName(i));

}
System.out.println("");
}
stmt.close();
closeConnection(connection);

 

My output with simple query:

Query for run: select sysdate from dual
Connected!
Make sure that ResultSet exists: 2016-06-01 19:54:26.372253
2016-06-01 19:54:26.372253 sysdate
Connection closed!

My output with hard query :

Query for run: SELECT
distinct
'AS' as layer...
/*there is a long query with a lot of JOINs and WHEREs*/
/*it returns results in other db-clients (for example DBeaver)*/

Connected!
Connection closed!

 

Do someone know what I'm doing wrong? Maybe it is a bug on jdbc?

 

I tried to get answer from stackoverflow, but unsuccessfully: http://stackoverflow.com/questions/36790178/jdbc-resultset-returns-null-from-stored-value-in-database

 

Comments

  • The problem was in my SQL-query.

    My JavaApp take SQL-query from file, that contains --comments. After my JavaApp convert it to String and send to DB.

     

    In Vertica you can check your queries using query:

    select * from query_requests
    order by start_timestamp desc

     Thanks!

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file