Search code examples
javamysqlms-accessjava-8ucanaccess

java.util.regex.PatternSyntaxException with UCanAccess


I am trying to connect to an Access database with Java 8 like in this answer :

Manipulating an Access database from Java without ODBC

I am unfamiliar with the creation/design of the DB.

The connection seems to work because I get a few error messages like this :

WARNING:Error in the metadata of the table MB02: table's row count in the metadata is 556 but 557 records have been found and loaded by UCanAccess. All will work fine, but it's better to repair your database.

And I have this method trying to pull something out of the DB with an SQL SELECT Statement :

public void searchDatabase()
        throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException {

    Connection con = DriverManager
            .getConnection("jdbc:ucanaccess:///C:/Users/Blabla.mdb");
    Statement stmt = con.createStatement();

    String query = "SELECT * FROM MB01";

    ResultSet resultSet = stmt.executeQuery(query);

    while(resultSet.next()){
        System.out.println(resultSet.getString(1));
    }

}

I keep getting this error :

Exception in thread "main" java.util.regex.PatternSyntaxException: Dangling meta character '?' near index 19 MB 01 BEZAHLT ??? ^ at java.util.regex.Pattern.error(Unknown Source) at java.util.regex.Pattern.sequence(Unknown Source) at java.util.regex.Pattern.expr(Unknown Source) at java.util.regex.Pattern.compile(Unknown Source) at java.util.regex.Pattern.(Unknown Source) at java.util.regex.Pattern.compile(Unknown Source) at java.lang.String.replaceAll(Unknown Source) at net.ucanaccess.converters.SQLConverter.replaceWhiteSpacedTableNames0(SQLConverter.java:547) at net.ucanaccess.converters.SQLConverter.replaceWhiteSpacedTables(SQLConverter.java:526) at net.ucanaccess.converters.SQLConverter.convertSQL(SQLConverter.java:372) at net.ucanaccess.converters.SQLConverter.convertSQL(SQLConverter.java:472) at net.ucanaccess.jdbc.UcanaccessStatement.convertSQL(UcanaccessStatement.java:57) at net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:206) at DBCrawler.searchDatabase(DBCrawler.java:27)

Line 27 is where the error is thrown is :

ResultSet resultSet = stmt.executeQuery(query);

The thing is I can leave the query String empty or put any nonsense values in it and I still get the error.

Where do I start searching for the problem or how can I fix this?


Solution

  • I created an Access database with a table named 19 MB 01 BEZAHLT ??? and was able to reproduce your issue with UCanAccess 3.0.5. The problem will be was fixed in a future release of UCanAccess 3.0.6.