Giter Club home page Giter Club logo

spannm / ucanaccess Goto Github PK

View Code? Open in Web Editor NEW
14.0 5.0 2.0 5.42 MB

Open-source pure Java JDBC driver for Microsoft Access databases. Allows Java developers and client programs (e.g. OpenOffice, LibreOffice, SQuirreL) to read and write various versions of Access databases.

Home Page: https://spannm.github.io/ucanaccess/

License: Apache License 2.0

Java 91.30% HTML 8.61% Batchfile 0.05% Shell 0.03%
access driver jdbc microsoft msaccess purejava sql

ucanaccess's People

Contributors

albfan avatar bxparks avatar jamadei avatar spannm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

thr27 ivo-k

ucanaccess's Issues

Default column value applied when explicit NULL value specified on insert

UCanAccess version 5.1.2-SNAPSHOT

Attempting to insert an explicit NULL value into a column that is nullable and has a default value causes the default value to be inserted instead of the NULL value.

UCanAccess>create table zzz (id text(50) primary key, int_col integer null default 0);
UCanAccess>No rows affected

UCanAccess>insert into zzz (id) values ('int_col omitted');
UCanAccess>1 row(s) affected

UCanAccess>select * from zzz;

·-----------------+---------·
| id              | int_col |
·-----------------+---------·
| int_col omitted |       0 |
·-----------------+---------·

UCanAccess>insert into zzz (id, int_col) values ('int_col explicit NULL', NULL);
UCanAccess>1 row(s) affected

UCanAccess>select * from zzz;

·-----------------------+---------·
| id                    | int_col |
·-----------------------+---------·
| int_col explicit NULL |       0 |
| int_col omitted       |       0 |
·-----------------------+---------·

UCanAccess>insert into zzz (id, int_col) values ('int_col some value', 123);
UCanAccess>1 row(s) affected

UCanAccess>select * from zzz;

·-----------------------+---------·
| id                    | int_col |
·-----------------------+---------·
| int_col explicit NULL |       0 |
| int_col omitted       |       0 |
| int_col some value    |     123 |
·-----------------------+---------·

The same behaviour is observed for Integer, Long Integer, Double, Decimal, and Short Text columns.

jquery version in doc\website\htdocs is vulnerable

Hi everybody,
thanks to all to maintaining this project alive.

Should it be possible to update jquery-3.2.1.min.js embedded in doc\website\htdocs\ to a less-vulnerable and more recent version?
It shouldn't be heavily impacting.

Thanks and Best Regards,
M.

Improvement: Exclude ODBC Tables

We have a lot of ODBC based Tables in our access databases.

ucanaccess is unable to load the access database because it fails to load these with the following error:

UCAExc:::5.1.0 TableDefinition has no data access (Db=Test1.accdb; Table=some_odbc_table_name

As ucanaccess will probably never be able to import ODBC based tables, it should exclude ODBC tables from the list of tables.

I would propose ... function createTables in src\main\java\net\ucanaccess\converters\LoadJet.java should check if table is ODBC_LINK and not add them to the list.

Line: 1070 ...

                if (t2 != null && t != null && !tn.startsWith("~")) {
                    
                    TableMetaData tableMetaData = t2.getDatabase().getTableMetaData(tn);
                    if (tableMetaData.getType() == TableMetaData.Type.LINKED_ODBC) {
                        logger.log(Level.WARNING, "Table {0} is linked to an ODBC table. Skipped ...", tn);
                        unresolvedTables.add(tn);
                    }else{
                        createTable(t);
                        loadingOrder.add(t.getName());
                    }
                }
...

Enable Discussions

Enable the Discussions tab on this GitHub project for public discussions.

Multiple threads failed to create table simultaneously

Version: ucanaccess 5.0.1;jdk 1.8.0
Problem:
i need to create and write different mdb files with multiple threads,the mdbs have different table struct;i found that when A thread creates Table A, and B thread sometimes will report an error when creating Table B. The reason for the error is due to the influence of A thread;
some log belows:

[DEBUG] 2024-06-26 18:09:05.803 [pool-2-thread-3] MdbWriter - CreateDb Url:jdbc:ucanaccess:///home/gm/GM4C/Bin/./index.mdb;newDatabaseVersion=V2003,SQL:CREATE TABLE PICINDEX ( IDX INTEGER NOT NULL PRIMARY KEY, POLEID VARCHAR(50), SETLOC VARCHAR(50), KM DOUBLE, ST VARCHAR(50), TUNNEL VARCHAR(50), DETECTDATE VARCHAR(50), MDirection VARCHAR(50), SPEED DOUBLE, CAMERANO VARCHAR(50), PATH VARCHAR(50), POLENUM VARCHAR(50), FRONT DOUBLE, BACK DOUBLE, FILEPRE VARCHAR(50), AllReadState VARCHAR(50), CorrectState VARCHAR(50), OldPoleNum VARCHAR(50), DataState VARCHAR(50));

[DEBUG] 2024-06-26 18:09:05.803 [pool-2-thread-2] MdbWriter - CreateDb Url:jdbc:ucanaccess:///home/gm/GM4C/Bin/./FaultIndex.mdb;newDatabaseVersion=V2003,SQL:CREATE TABLE FaultLevel ( LevelID VARCHAR(50) NOT NULL PRIMARY KEY, LevelName VARCHAR(50), DelFlag VARCHAR(50), Memo VARCHAR(100));

[ERROR] 2024-06-26 18:09:05.846 [pool-2-thread-2] MdbWriter - CreateDb Failed,file:/home/gm/GM4C/Bin/./FaultIndex.mdb,Err:UCAExc:::4.x.x java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: PICINDEX

thread-3 should create PICINDEX,thread-2 should create FaultLevel,however, thread-2 create table failed,the error is " user lacks privilege or object not found: PICINDEX",but PICINDEX should create by thread-3.

when i use just one thread to deal all mdb files sequentially,no error wiil happen.
Question:
do you have know this problem,or does version 5.1.1 has fixed this problem.

Complete bin.zip distribution for download

Suggestion:

Earlier versions of UCanAccess made a complete bin.zip file available for download from SourceForge, e.g., UCanAccess-5.0.1.bin.zip contained

UCanAccess-5.0.1.bin
    lib
        commons-lang3-3.8.1.jar  
        commons-logging-1.2.jar  
        hsqldb-2.5.0.jar  
        jackcess-3.0.1.jar
    licenses
        apache-license-2.0.txt  
        hsqldb_lic.txt  
        hypersonic_lic.txt  
        lgpl-2.1.txt  
        licenses.txt
    loader
        ucanload.jar
    console.bat  
    console.sh  
    copyright.txt
    ucanaccess-5.0.1.jar  
    version.txt

This was very convenient for people who wanted to use UCanAccess without necessarily having a Java project that could take advantage of Maven. One example would be a Python project that could use UCanAccess along with JayDeBeApi as described here. The console.bat and console.sh utilities were also very useful for troubleshooting.

Add shading to -fat.jar

The new fat jar added in #7 helpfully bundles all driver dependencies. For example, in ucanaccess-5.1.2-20240327.163958-57-fat.jar I can see

  • com.zaxxer.sparsebits
  • org.apache.commons
  • org.hsqldb

As only one version of any Java class can be loaded it is likely that the ucanaccess driver will not be compatible with other jars that require different versions of those dependencies (either ucanaccess will be poisoned or it will poison others). This is true for the fat or standalone jars.

Adding shading to the fat jar would make ucanaccess a model citizen, safe from possible foreign interactions. This is what we do locally rather than using anything pre-built.

I believe the important bits of our own shading instructions (kinda crude, sorry) for rebuilding ucanaccess are the following (note that ucanaccess doesn't strictly need jackcess-encrypt but users do if they are dealing with encrypted databases - so I guess this request includes packing jackcess-encrypt in there).

    d) in your maven project pom.xml, add dependencies to 
        - ucanaccess
	      https://central.sonatype.com/artifact/io.github.spannm/ucanaccess
        - jackcess-encrypt (used by our code)
	      https://mvnrepository.com/artifact/com.healthmarketscience.jackcess/jackcess-encrypt
    e) add maven-shade-plugin to pom.xml
    f) view the dependency tree of the project via maven:
	    > mvn dependency:tree
    g) inspect the dependency tree, and from top to bottom, add the artifacts that need to be included in your pom.xml
    h) download these artifacts if your IDE hasn't automatically done so
    i) inspect each artifact, determine the patterns that include the entire contents of the artifact (other than META-INF), and relocate them to jdbc.ucanaccess.shaded.* in your pom.xml
    j) in your pom.xml, ensure that the project version (line 10) matches the version of ucanaccess that was added as a dependency in step d (line 15). (See FMEENGINE-63096)
    k) package a JAR by running:
        > mvn clean package

HSQLDB v2.7.2 incompatible

Issue

Currently UCanAccess depends on HSQLDB v2.7.1, but at some point we will have to update this dependency.

I updated HSQLDB to v2.7.2, to check if it runs stable, but it doesn't.

→ Is there something we can do in the UCanAccess library to avoid the error (see below) or is it possibly a bug in HSQLDB?

Error

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::5.1.1 Cannot invoke "org.hsqldb.Statement.getTableNamesForRead()" because "<parameter1>.sessionContext.currentStatement" is null
    at net.ucanaccess.jdbc.UcanaccessSQLException.wrap(UcanaccessSQLException.java:123)
    at net.ucanaccess.util.Try.orThrow(Try.java:298)
    at net.ucanaccess.jdbc.UcanaccessStatement.tryCatch(UcanaccessStatement.java:406)
    at net.ucanaccess.jdbc.UcanaccessStatement.executeUpdate(UcanaccessStatement.java:165)
    at my.namespace.MyTest.TestUCanAccessWithHSQLDBv272(MyTest.java:*)

Reproducer

@Test
public void TestUCanAccessWithHSQLDBv272() throws SQLException, IOException {
    try(var conn = openNewDatabase(); var stmt = conn.createStatement()) {
        // create new table and add some data
        stmt.executeUpdate("CREATE TABLE Tbl (ID INT NOT NULL PRIMARY KEY, Txt VARCHAR(255))");
        stmt.executeUpdate("INSERT INTO Tbl (ID, Txt) VALUES (1, 'One'), (2, 'Two'), (3, 'Tre')");
        
        // query data
        try(var row = stmt.executeQuery("SELECT ID, Txt FROM Tbl ORDER BY ID")) {
            assertTrue(row.next()); assertEquals(1, row.getInt(1)); assertEquals("One", row.getString(2));
            assertTrue(row.next()); assertEquals(2, row.getInt(1)); assertEquals("Two", row.getString(2));
            assertTrue(row.next()); assertEquals(3, row.getInt(1)); assertEquals("Tre", row.getString(2));
        }
        // update data
        stmt.executeUpdate("UPDATE Tbl SET Txt = 'Row ' || Txt");
        try(var row = stmt.executeQuery("SELECT Txt FROM Tbl ORDER BY ID")) {
            assertTrue(row.next()); assertEquals("Row One", row.getString(1));
            assertTrue(row.next()); assertEquals("Row Two", row.getString(1));
            assertTrue(row.next()); assertEquals("Row Tre", row.getString(1));
        }
        
        // remove data
        stmt.executeUpdate("DELETE FROM Tbl");
        try(var row = stmt.executeQuery("SELECT * FROM Tbl")) {
            assertFalse(row.next());    // no data
        }
    }
}

private static Connection openNewDatabase() throws SQLException, IOException {
    var tempDbFile = Path.of(System.getProperty("java.io.tmpdir"), "TestDatabase.accdb");
    var dbFileLocation = tempDbFile.toString().replace('\\', '/');
    
    tempDbFile.toFile().delete();    // delete from previous test run
    
    return DriverManager.getConnection("jdbc:ucanaccess://" + dbFileLocation + ";newdatabaseversion=V2016");
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.