java.lang.NullPointerException
at craftsman.spy.SpyConnection.getMetaData(SpyConnection.java:252)
at net.ucanaccess.jdbc.DBReference.getHSQLDBConnection(DBReference.java:346)
at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:190)
meaning .getHSQLDBConnection returns null
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The stacktrace you posted can't be generated by the situation you described, unless you're using a very out-of-date ucanaccess version. Please upgrade ucanaccess to the the latest version and send the resulting stacktrace again, along the jdbc url used (you omitted the call to the DriverManager).
Last edit: Marco Amadei 2016-01-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I call DriverManager.getConnection(...) . The ideea is the connection works when we do not register spy driver and it does not when we register it. I tested also with the last version and get :
Okay, I see. This time the stacktrace is meaningful. Once I have reproduced the issue within spy, I'll let you know my findings(today I can't, but hopefully tomorrow I should be able to).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry for the late answer, this code works fine for me:
publicstaticvoidmain(String[]args)throwsSQLException,ClassNotFoundException,InstantiationException,IllegalAccessException{System.setProperty("spy.driver","net.ucanaccess.jdbc.UcanaccessDriver");DriverManager.registerDriver(newSpyDriver());System.setProperty("spy.log","D:/jdbc-spy.log");Connectionconn=DriverManager.getConnection("jdbc:spy:net.ucanaccess.jdbc.UcanaccessDriver:ucanaccess://C:\\db\\test.accdb");Statementst=conn.createStatement();ResultSetrs=st.executeQuery("select * from ab");while(rs.next()){...}...}
Last edit: Marco Amadei 2016-01-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Nothing wrong in the ucanaccess behaviour.
So, you deregister each driver forcing each connection be wrapped by spy. Unfortunately ucanaccess in turn wraps another driver: the hsqldb driver. In the wrapping chain spy-> ucanaccess-> spy-> hsqldb spy fails some association. Therefore spy invokes ucanaccess to connect to an hsqldb url(resulting in a null returned by ucanaccess and so in a NullPointerException).
You know, supporting this approach wouldn't be worth for me but...
Immediately after the drivers' deregistration, you have to re-re-register the hsqldb driver (which fortunately isn't in your list and so hopefully it's used just by ucanaccess):
DriverManager.registerDriver(new org.hsqldb.jdbc.JDBCDriver());
Those young java hackers...
Last edit: Marco Amadei 2016-01-13
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We register the spy driver (http://zer0.free.fr/craftsman/spy.php) like:
System.setProperty("spy.driver", "net.ucanaccess.jdbc.UcanaccessDriver");
DriverManager.registerDriver(new SpyDriver());
System.setProperty("spy.log", "D:/logs/jdbc-spy.log");
When we try to connect we get:
java.lang.NullPointerException
at craftsman.spy.SpyConnection.getMetaData(SpyConnection.java:252)
at net.ucanaccess.jdbc.DBReference.getHSQLDBConnection(DBReference.java:346)
at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:190)
The stacktrace you posted can't be generated by the situation you described, unless you're using a very out-of-date ucanaccess version. Please upgrade ucanaccess to the the latest version and send the resulting stacktrace again, along the jdbc url used (you omitted the call to the DriverManager).
Last edit: Marco Amadei 2016-01-06
Hi.
I call DriverManager.getConnection(...) . The ideea is the connection works when we do not register spy driver and it does not when we register it. I tested also with the last version and get :
java.util.concurrent.ExecutionException: net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.3.1 nullnet.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.3.1 nulljava.lang.NullPointerException
UCAExc:::3.0.3.1 null
net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:260)
craftsman.spy.SpyDriver.connect(SpyDriver.java:265)
java.sql.DriverManager.getConnection(DriverManager.java:571)
java.sql.DriverManager.getConnection(DriverManager.java:215)
.....
null
craftsman.spy.SpyConnection.getMetaData(SpyConnection.java:252)
net.ucanaccess.jdbc.DBReference.getHSQLDBConnection(DBReference.java:444)
net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:227)
craftsman.spy.SpyDriver.connect(SpyDriver.java:265)
java.sql.DriverManager.getConnection(DriverManager.java:571)
java.sql.DriverManager.getConnection(DriverManager.java:215)
.....
The jdbc url used is like :
jdbc:ucanaccess://D:/Temp/access/test.accdb;showschema=true
Okay, I see. This time the stacktrace is meaningful. Once I have reproduced the issue within spy, I'll let you know my findings(today I can't, but hopefully tomorrow I should be able to).
Sorry for the late answer, this code works fine for me:
Last edit: Marco Amadei 2016-01-12
Hi.
Sorry to forget about this.
We do one more thing just before we register the Spy driver, we deregister all existing drivers , meaning ucanaccess driver is also unregistered:
and we use :
without spy.
We can connect like this to any jdbc driver we have (using the normal url) like oracle, mysql, postgresql, derby and so on, except ucanaccess.
Nothing wrong in the ucanaccess behaviour.
So, you deregister each driver forcing each connection be wrapped by spy. Unfortunately ucanaccess in turn wraps another driver: the hsqldb driver. In the wrapping chain spy-> ucanaccess-> spy-> hsqldb spy fails some association. Therefore spy invokes ucanaccess to connect to an hsqldb url(resulting in a null returned by ucanaccess and so in a NullPointerException).
You know, supporting this approach wouldn't be worth for me but...
Immediately after the drivers' deregistration, you have to re-re-register the hsqldb driver (which fortunately isn't in your list and so hopefully it's used just by ucanaccess):
DriverManager.registerDriver(new org.hsqldb.jdbc.JDBCDriver());
Those young java hackers...
Last edit: Marco Amadei 2016-01-13
Yes. It makes sense if a driver uses another driver. I will do as suggested.