Overview of this topic
- Problem
- Test
- Source code
- Successful execution when only ucanload.jar in the CLASSPATH
- Failed execution when hsqldb.jar (latest version) is added to the CLASSPATH
Problem
Hello,
Can I use UCanAccess in a Java application that uses hsqldb (latest version) as an embedded db?
The hsqldb.jar (latest version) seems to be in conflict with the hsqldb.jar (older version) from the UCanAccess distribution.
For the embedded db, I plan to add hsqldb.jar (latest version) to the CLASSPATH. This seems to cause problems for UCanAccess.
Thanks for any comments on this.
Carl
Test
As a test, after removing hsqldb.jar (latest version) from the CLASSPATH, I have successfully used UCanAccess according to the 2 ways described here:
In this example I just added the ucanload.jar to the CLASSPATH and set a Java system property named UCANACCESS_HOME.
It seems to work fine regardless of setting the -Dproperty=value or not ( maybe this is relevant for my question ).
In "Eclipse (GUI) / Run Configurations / (x)= Arguments / VM arguments:" I put the following:
-DUCANACCESS_HOME=C:\xyz\Carl\workspace\myProject2\UCanAccess-4.0.2-bin
When hsqldb.jar (latest version) is added to the CLASSPATH (for the embedded db to work) UCanAccess seems to have a problem.
Please find below a source code example and the output from a successful and a failed execution depending on what is added to the CLASSPATH.
The database file is attached. In this example the database file is stored in the folder:
C:\xyz\Carl\db1carlsTest.accdb
Source code
importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.ResultSetMetaData;importjava.sql.DatabaseMetaData;importjava.sql.SQLException;importjava.sql.Statement;publicclassDrive{publicDrive(){//displaynewpropertiesSystem.getProperties().list(System.out);Stringurl="jdbc:ucanaccess://C:/xyz/Carl/db1carlsTest.accdb";Connectioncon;Statementstmt;Stringquery="SELECT TOP 10 T2.id, T1.M_NB, T1.M_FL_DATE, T1.M_FL_UNIT, T2.MAX_DATE, T2.MAX_UNIT FROM TBL_KEY_COLS T1 INNER JOIN TBL_KEY_COLS_II T2 ON T1.M_NB = T2.M_NB;";try{//Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");//Whenhavingfive.jarfiles(fromUCanAccess)intheCLASSPATH.Class.forName("net.ucanaccess.jdbc.UcanloadDriver");//Whenhavingonlyucanload.jar(fromUCanAccess)intheCLASSPATH.con=DriverManager.getConnection(url,"","");stmt=con.createStatement();DatabaseMetaDatadbmd=con.getMetaData();ResultSetrs=stmt.executeQuery(query);ResultSetMetaDatarsmd=rs.getMetaData();StringkeysCSV=",";//Loopovercolumnsandcollectprimarykeys.BELOWfor(intcolumn=1;column<=rsmd.getColumnCount();column++){Stringcatalog=rsmd.getCatalogName(column);Stringschema=rsmd.getSchemaName(column);Stringtable=rsmd.getTableName(column);ResultSetrsKey=dbmd.getPrimaryKeys(catalog,schema,table);//LoopoverprimarykeysrelatedtoatableidentifiedbyacolumnfromtheSQLresultset.BELOWwhile(rsKey.next()){if(!(keysCSV.indexOf(","+rsKey.getString("COLUMN_NAME")+",")>-1)){keysCSV=keysCSV+rsKey.getString("COLUMN_NAME")+",";}}//LoopoverprimarykeysrelatedtoatableidentifiedbyacolumnfromtheSQLresultset.ABOVErsKey.close();}//Loopovercolumnsandcollectprimarykeys.ABOVESystem.out.println("");System.out.println("Key columns found: "+keysCSV);System.out.println("");System.out.println("\n\nPrint below from the resultset from MS Access");while(rs.next()){Stringid=rs.getString("id");Stringnb=rs.getString("M_NB");StringflDate=rs.getString("M_FL_DATE");StringflUnit=rs.getString("M_FL_UNIT");StringmaxDate=rs.getString("MAX_DATE");StringmaxUnit=rs.getString("MAX_UNIT");System.out.println(id+"\t"+nb+"\t"+flDate+"\t"+flUnit+"\t"+maxDate+"\t"+maxUnit);}rs.close();stmt.close();con.close();}catch(SQLExceptionex){System.err.println("SQLException: "+ex.getMessage());ex.printStackTrace();}catch(ClassNotFoundExceptione){e.printStackTrace();}}publicstaticvoidmain(String[]args){newDrive();}}
Successful execution when only ucanload.jar in the CLASSPATH
I can reproduce the issue using my own test database. It seems to be directly related to the .getPrimaryKeys call. With both ucanload.jar and hsqldb-2.4.0.jar on my Eclipse build path I can successfully do a normal SELECT on a table in the Access database (once I get past all of the WARNING messages), but when I try to do
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.x.x java.lang.ArrayIndexOutOfBoundsException: 1
at net.ucanaccess.jdbc.UcanaccessDatabaseMetadata.getPrimaryKeys(UcanaccessDatabaseMetadata.java:854)
at com.example.ucanaccessdemo.UCanAccessDemoMain.main(UCanAccessDemoMain.java:48)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hsqldb-2.4.0
UCanAccess-4.0.2
Overview of this topic
- Problem
- Test
- Source code
- Successful execution when only ucanload.jar in the CLASSPATH
- Failed execution when hsqldb.jar (latest version) is added to the CLASSPATH
Problem
Hello,
Can I use UCanAccess in a Java application that uses hsqldb (latest version) as an embedded db?
The hsqldb.jar (latest version) seems to be in conflict with the hsqldb.jar (older version) from the UCanAccess distribution.
For the embedded db, I plan to add hsqldb.jar (latest version) to the CLASSPATH. This seems to cause problems for UCanAccess.
Thanks for any comments on this.
Carl
Test
As a test, after removing hsqldb.jar (latest version) from the CLASSPATH, I have successfully used UCanAccess according to the 2 ways described here:
https://stackoverflow.com/questions/34464565/ucanaccess-home-system-variable-not-set/34469789#34469789
In this example I just added the ucanload.jar to the CLASSPATH and set a Java system property named UCANACCESS_HOME.
It seems to work fine regardless of setting the -Dproperty=value or not ( maybe this is relevant for my question ).
In "Eclipse (GUI) / Run Configurations / (x)= Arguments / VM arguments:" I put the following:
-DUCANACCESS_HOME=C:\xyz\Carl\workspace\myProject2\UCanAccess-4.0.2-bin
When hsqldb.jar (latest version) is added to the CLASSPATH (for the embedded db to work) UCanAccess seems to have a problem.
Please find below a source code example and the output from a successful and a failed execution depending on what is added to the CLASSPATH.
The database file is attached. In this example the database file is stored in the folder:
C:\xyz\Carl\db1carlsTest.accdb
Source code
Successful execution when only ucanload.jar in the CLASSPATH
-- listing properties -- (filtered by Carl)
.
.
.
UCANACCESS_HOME=C:\xyz\Carl\workspace\myP...
java.library.path=C:\Program Files\Java\jre1.8.0_131\bi...
.
.
.
Key columns found: ,ID,M_NB,M_FL_DATE,M_FL_UNIT,
Print below from the resultset from MS Access
1 3 1901-01-01 00:00:00.000000 lll 1901-01-01 00:00:00.000000 lll
2 3347385 2011-02-16 00:00:00.000000 EUR 2017-06-15 00:00:00.000000 EUR
2 3347385 2011-03-16 00:00:00.000000 EUR 2017-06-15 00:00:00.000000 EUR
2 3347385 2011-08-16 00:00:00.000000 EUR 2017-06-15 00:00:00.000000 EUR
2 3347385 2011-09-15 00:00:00.000000 EUR 2017-06-15 00:00:00.000000 EUR
2 3347385 2011-11-16 00:00:00.000000 EUR 2017-06-15 00:00:00.000000 EUR
2 3347385 2011-12-15 00:00:00.000000 EUR 2017-06-15 00:00:00.000000 EUR
2 3347385 2012-01-17 00:00:00.000000 EUR 2017-06-15 00:00:00.000000 EUR
2 3347385 2012-05-16 00:00:00.000000 EUR 2017-06-15 00:00:00.000000 EUR
2 3347385 2012-11-15 00:00:00.000000 EUR 2017-06-15 00:00:00.000000 EUR
Failed execution when hsqldb.jar (latest version) is added to the CLASSPATH
-- listing properties -- (filtered by Carl)
.
.
.
UCANACCESS_HOME=C:\xyz\Carl\workspace\myP...
java.library.path=C:\Program Files\Java\jre1.8.0_131\bi...
.
.
.
WARNING:Function already added: CREATE FUNCTION SLN(par0 DOUBLE,par1 DOUBLE,par2 DOUBLE) RETURNS DOUBLE LANGUAGE JAVA DETERMINISTIC NO SQL EXTERNAL NAME 'CLASSPATH:net.ucanaccess.converters.Functions.sln'
WARNING:Function already added: CREATE FUNCTION STRING(par0 INTEGER,par1 LONGVARCHAR) RETURNS LONGVARCHAR LANGUAGE JAVA DETERMINISTIC NO SQL EXTERNAL NAME 'CLASSPATH:net.ucanaccess.converters.Functions.string'
WARNING:Function already added: CREATE FUNCTION PPMT(par0 DOUBLE,par1 INTEGER,par2 INTEGER,par3 DOUBLE,par4 DOUBLE,par5 DOUBLE) RETURNS DOUBLE LANGUAGE JAVA DETERMINISTIC NO SQL EXTERNAL NAME 'CLASSPATH:net.ucanaccess.converters.Functions.ppmt'
WARNING:Function already added: CREATE FUNCTION formulaToNumeric(par0 TIMESTAMP,par1 LONGVARCHAR) RETURNS DOUBLE LANGUAGE JAVA DETERMINISTIC NO SQL EXTERNAL NAME 'CLASSPATH:net.ucanaccess.converters.Functions.formulaToNumeric'
WARNING:Function already added: CREATE FUNCTION DATEPARTWA(par0 LONGVARCHAR,par1 LONGVARCHAR,par2 INTEGER,par3 INTEGER) RETURNS INTEGER LANGUAGE JAVA DETERMINISTIC NO SQL EXTERNAL NAME 'CLASSPATH:net.ucanaccess.converters.Functions.datePart'
WARNING:Function already added: CREATE FUNCTION EQUALS(par0 OBJECT,par1 OBJECT) RETURNS BOOLEAN LANGUAGE JAVA DETERMINISTIC NO SQL EXTERNAL NAME 'CLASSPATH:net.ucanaccess.converters.Functions.equals'
.
.
.
The listing of warnings goes on...
.
.
.
Last edit: Carl Kjellberg 2017-06-15
I can reproduce the issue using my own test database. It seems to be directly related to the
.getPrimaryKeys
call. With bothucanload.jar
andhsqldb-2.4.0.jar
on my Eclipse build path I can successfully do a normal SELECT on a table in the Access database (once I get past all of the WARNING messages), but when I try to doI get
Hi Gord,
Thank you for the feedback.
Do you know if there are any plans to use the latest version of hsqldb.jar for UCanAccess?
I guess that would solve my problem and make UCanAccess even more useful.
However, a suggestion on a workarround is also welcome.
Best Regards
Carl