Hello, I am trying out the Simba 4.1 JDBC driver. I had a question about my ResultSet. It seems that each time I run my N1QL query, I may get a different number of columns. I ran this test using Java 8 for my client, against a 1 node cluster running version 4.0.0-dp.
For example, here are two runs of the same program.
About to get connection to Couchbase…
About to create statement…
About to execute query…
executeQuery() took 3154 ms.
The result has 11 columns.
Found 7303 query results.
Goodbye.
And a different run…
About to get connection to Couchbase…
About to create statement…
About to execute query…
executeQuery() took 2961 ms.
The result has 9 columns.
Found 7303 query results.
Goodbye.
Here is my code,
System.out.println("About to get connection to Couchbase...");
conn = DriverManager.getConnection("jdbc:couchbase://hostname:8093/default;queryEnabled=1",
connectionProps);
System.out.println("About to create statement...");
stmt = conn.createStatement();
System.out.println("About to execute query...");
t1 = System.currentTimeMillis();
rs = stmt.executeQuery("select * from `beer-sample`;");
t2 = System.currentTimeMillis();
System.out.println("executeQuery() took " + ( t2 - t1 ) + " ms.");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
System.out.println("The result has " + numberOfColumns + " columns.");
int resultsFound = 0;
while (rs.next()) {
resultsFound++;
}
System.out.println("Found " + resultsFound + " query results." );
}
catch (Exception e) {
System.out.println("Caught exception: " + e);
}
System.out.println("Goodbye." );