Не могу создать таблицу в Java для доступа - PullRequest
0 голосов
/ 15 ноября 2018

Я не могу создать таблицу для Access, но я могу читать данные или отправлять данные в таблицу, созданную вручную.Остановка программы при создании команды SQL таблицы.Я также установил Access-> File-> Settings-> General.

public class DB {
  final String path = "C:...database1.accdb";
  final String url ="jdbc:ucanaccess://"+path;

    Connection conn = null;
    Statement createStatement = null;
    DatabaseMetaData dbmd = null;

    public DB() {
        try {
            try {
                Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            conn = DriverManager.getConnection(url);
        } catch (SQLException ex) {
            System.out.println(""+ex);
        }

        if (conn != null){
            try {
                createStatement = conn.createStatement();
            } catch (SQLException ex) {

                System.out.println(""+ex);
            }
        }

        try {           
            dbmd = conn.getMetaData();
        } catch (SQLException ex) {
            System.out.println(""+ex);
        }

        try {
            ResultSet rs = dbmd.getTables(null, "APP", "USERS", null);
            if(!rs.next())
            {
         createStatement.execute("CREATE TABLE users (name TEXT(50))");
            }
        } catch (SQLException ex) {
            System.out.println(""+ex);
        }       
    }
}

Информация об ошибке:

java.lang.UnsupportedOperationException: Cannot write indexes of this type due to unsupported collating sort order SortOrder[1038(0)] for text index
    at com.healthmarketscience.jackcess.impl.IndexData$ReadOnlyColumnDescriptor.writeNonNullValue(IndexData.java:1739)
    at com.healthmarketscience.jackcess.impl.IndexData$ColumnDescriptor.writeValue(IndexData.java:1424)
    at com.healthmarketscience.jackcess.impl.IndexData.createEntryBytes(IndexData.java:1222)
    at com.healthmarketscience.jackcess.impl.IndexData.prepareAddRow(IndexData.java:561)
    at com.healthmarketscience.jackcess.impl.IndexData.prepareAddRow(IndexData.java:539)
    at com.healthmarketscience.jackcess.impl.TableImpl.addRows(TableImpl.java:1595)
    at com.healthmarketscience.jackcess.impl.TableImpl.addRow(TableImpl.java:1461)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.addToSystemCatalog(DatabaseImpl.java:1363)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.addNewTable(DatabaseImpl.java:997)
    at com.healthmarketscience.jackcess.impl.TableCreator.createTable(TableCreator.java:165)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.createTable(DatabaseImpl.java:954)
    at com.healthmarketscience.jackcess.TableBuilder.toTable(TableBuilder.java:223)
    at net.ucanaccess.converters.Persist2Jet.createTable(Persist2Jet.java:405)
    at net.ucanaccess.commands.CreateTableCommand.persist(CreateTableCommand.java:99)
    at net.ucanaccess.jdbc.UcanaccessConnection.flushIO(UcanaccessConnection.java:313)
    at net.ucanaccess.jdbc.UcanaccessConnection.commit(UcanaccessConnection.java:203)
    at net.ucanaccess.jdbc.AbstractExecute.executeBase(AbstractExecute.java:147)
    at net.ucanaccess.jdbc.Execute.execute(Execute.java:52)
    at net.ucanaccess.jdbc.UcanaccessStatement.execute(UcanaccessStatement.java:143)
    at meas_data_logger_v10.DB.<init>(DB.java:66)
    at meas_data_logger_v10.meas_data_logger_main_frame$1.run(meas_data_logger_main_frame.java:53)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

Если я изменю

createStatement.execute("CREATE TABLE users (name int(50))");

myСообщение об ошибке только

net.ucanaccess.jdbc.UcanaccessSQLException: unexpected token: (

Пожалуйста, помогите, если можете!

...