JDBC query - NPE
bwallis42 May 16, 2012 6:48 AMI'm trying some JDBC queries from a client using the REST interface. The code is:
{code}
// Load the database driver
Class.forName("org.modeshape.jdbc.JcrDriver");
// Get a connection to the database
Connection conn = DriverManager.getConnection("jdbc:jcr:http://localhost:8080/modeshape-rest?repositoryName=DocumentStore&workspace=default&user=admin&password=admin");
// Get a statement from the connection
Statement stmt = conn.createStatement();
// Execute the query
ResultSet rs = stmt.executeQuery("SELECT * FROM [inf:documentGroup]");
{code}
the stmt.executeQuery() statement is line 39 (in the stack trace below).
the debug output includes the http traffic and the raw json result looks like what I was expecting but then the JDBC code gets a NPE.
{noformat}
139 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection - Sending request: POST /modeshape-rest/DocumentStore/default/query HTTP/1.1
139 [main] DEBUG org.apache.http.wire - >> "POST /modeshape-rest/DocumentStore/default/query HTTP/1.1[\r][\n]"
139 [main] DEBUG org.apache.http.wire - >> "Content-Type: application/jcr+sql2[\r][\n]"
139 [main] DEBUG org.apache.http.wire - >> "Content-Length: 33[\r][\n]"
139 [main] DEBUG org.apache.http.wire - >> "Host: localhost:8080[\r][\n]"
139 [main] DEBUG org.apache.http.wire - >> "Connection: Keep-Alive[\r][\n]"
139 [main] DEBUG org.apache.http.wire - >> "User-Agent: Apache-HttpClient/4.1.2 (java 1.5)[\r][\n]"
139 [main] DEBUG org.apache.http.wire - >> "Authorization: Basic YWRtaW46YWRtaW4=[\r][\n]"
139 [main] DEBUG org.apache.http.wire - >> "[\r][\n]"
139 [main] DEBUG org.apache.http.headers - >> POST /modeshape-rest/DocumentStore/default/query HTTP/1.1
139 [main] DEBUG org.apache.http.headers - >> Content-Type: application/jcr+sql2
139 [main] DEBUG org.apache.http.headers - >> Content-Length: 33
139 [main] DEBUG org.apache.http.headers - >> Host: localhost:8080
139 [main] DEBUG org.apache.http.headers - >> Connection: Keep-Alive
140 [main] DEBUG org.apache.http.headers - >> User-Agent: Apache-HttpClient/4.1.2 (java 1.5)
140 [main] DEBUG org.apache.http.headers - >> Authorization: Basic YWRtaW46YWRtaW4=
140 [main] DEBUG org.apache.http.wire - >> "SELECT * FROM [inf:documentGroup]"
217 [main] DEBUG org.apache.http.wire - << "HTTP/1.1 200 OK[\r][\n]"
217 [main] DEBUG org.apache.http.wire - << "Server: Apache-Coyote/1.1[\r][\n]"
217 [main] DEBUG org.apache.http.wire - << "X-Powered-By: Servlet/3.0; JBossAS-6[\r][\n]"
218 [main] DEBUG org.apache.http.wire - << "Content-Type: */*[\r][\n]"
218 [main] DEBUG org.apache.http.wire - << "Content-Length: 841[\r][\n]"
218 [main] DEBUG org.apache.http.wire - << "Date: Wed, 16 May 2012 10:18:57 GMT[\r][\n]"
218 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
218 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection - Receiving response: HTTP/1.1 200 OK
218 [main] DEBUG org.apache.http.headers - << HTTP/1.1 200 OK
218 [main] DEBUG org.apache.http.headers - << Server: Apache-Coyote/1.1
218 [main] DEBUG org.apache.http.headers - << X-Powered-By: Servlet/3.0; JBossAS-6
218 [main] DEBUG org.apache.http.headers - << Content-Type: */*
218 [main] DEBUG org.apache.http.headers - << Content-Length: 841
218 [main] DEBUG org.apache.http.headers - << Date: Wed, 16 May 2012 10:18:57 GMT
218 [main] DEBUG org.apache.http.client.protocol.ResponseAuthCache - Caching 'basic' auth scheme for http://localhost:8080
218 [main] DEBUG org.apache.http.impl.client.DefaultHttpClient - Connection can be kept alive indefinitely
218 [main] DEBUG org.apache.http.wire - << "{"types":{"jcr:uuid":"STRING","jcr:primaryType":"STRING","jcr:created":"DATE","jcr:createdBy":"STRING","jcr:path":"STRING","jcr:name":"STRING","jcr:score":"DOUBLE","mode:localName":"STRING","mode:depth":"LONG"},"rows":[{"jcr:uuid":"c0f27e80-339f-4b0b-9484-699f37f74ebc","jcr:primaryType":"inf:documentGroup","jcr:created":"2012-05-15T14:52:48.764+10:00","jcr:createdBy":"username","jcr:path":"\/inf:documentGroup","jcr:name":"inf:documentGroup","jcr:score":"4.355734825134277","mode:localName":"documentGroup","mode:depth":"1"},{"jcr:uuid":"58d09ead-d87f-4841-a4d0-a7c151ff174c","jcr:primaryType":"inf:documentGroup","jcr:created":"2012-05-15T15:23:02.907+10:00","jcr:createdBy":"username","jcr:path":"\/inf:documentGroup[2]","jcr:name":"inf:documentGroup","jcr:score":"4.355734825134277","mode:localName":"documentGroup","mode:depth":"1"}]}"
219 [main] DEBUG org.apache.http.impl.conn.SingleClientConnManager - Releasing connection org.apache.http.impl.conn.SingleClientConnManager$ConnAdapter@3bc0f2e5
220 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection - Connection shut down
java.lang.NullPointerException
at org.modeshape.jdbc.JcrResultSetMetaData.getColumnCount(JcrResultSetMetaData.java:82)
at org.modeshape.jdbc.JcrResultSet.<init>(JcrResultSet.java:100)
at org.modeshape.jdbc.JcrStatement.execute(JcrStatement.java:430)
at org.modeshape.jdbc.JcrStatement.executeQuery(JcrStatement.java:479)
at au.com.infomedix.harvey.documentstore.jcr.JDBCTest.main(JDBCTest.java:39)
{noformat}
On examination of the code in JcrStatement it seems that the result returned by the execute function is null. Looking at HttpRepositoryDelegate.execute() it seems that it will always return a null. This code just looks like it is incomplete. Is there a way to get this to work?
thanks,