Reading .mdb files using UCanAccess returns column names in all UPPERCASE

In the middle, I switched from the JDBC-ODBC bridge driver to the UCanAccess driver.

In doing so, I ran into the following problem: the UCanAccess driver returns all columns in UPPERCASE, but I need them to be CamelCase.

Any ideas?

thank!

+4
source share
1 answer

With UCanAccess, version 3.x, released in August 2015, ResultSetMetaDatanow returns column names in the mixed case, if that's how they are defined in the database. (That is, they are no longer forced to TOP.)


(Original answer)

UCanAccess Jackcess, Jackcess. , UCanAccess 2.0.4 Jackcess 2.0.4,...

package ucanaccesstest;

import java.io.File;
import java.io.IOException;
import java.sql.*;
import com.healthmarketscience.jackcess.*;

public class UCanAccessTestMain {

    public static void main(String[] args) {
        String dbFileSpec = "C:/Users/Public/mdbTest.mdb";
        String tableName = "ucaTest";

        // UCanAccess
        try (Connection conn = DriverManager.getConnection("jdbc:ucanaccess://" + dbFileSpec)) {
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT * FROM [" + tableName + "] WHERE False");
            ResultSetMetaData rsmd = rs.getMetaData();
            System.out.println("Column names as reported by ResultSetMetaData:");
            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                System.out.println(rsmd.getColumnName(i));
            }
            rs.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace(System.out);
        }
        System.out.println();

        // Jackcess
        try (Database db = DatabaseBuilder.open(new File(dbFileSpec))) {
            Table tbl = db.getTable(tableName);
            System.out.println("Column names as reported by Jackcess:");
            for (Column col : tbl.getColumns()) {
                System.out.println(col.getName());
            }
        } catch (IOException e) {
            e.printStackTrace(System.out);
        }
    }

}

... :

Column names as reported by ResultSetMetaData:
ID
FIELD1
FIELD2

Column names as reported by Jackcess:
Id
Field1
Field2
+3

Source: https://habr.com/ru/post/1535738/


All Articles