简体   繁体   中英

GraalVM native-image and Oracle ojdbc11-21.1

I am currentliy experimenting with the native-image tool from GraalVM and the Oracle-driver. The source code compiles and generates an exe File without errors. But when I start the program it gets a java.lang.RuntimeException: Missing character set id 170 not loaded at image build time.

I am connecting to a database with characterset NLS_CHARACTERSET = EE8MSWIN1250. When I use a database with NLS_CHARACTERSET = AL32UTF8 the connection works fine.

I am using GraalVM CE 21.0.0.2 (build 11.0.10+8-jvmci-21.0-b06 and ojdbc11-21.1.0.0.jar on a Windows 10 64bit Computer.

Below ist the error message and the source code. I used the sample code from https://github.com/oracle/oracle-db-examples/blob/master/java/jdbc/ConnectionSamples/DataSourceSample.java

Exception in thread "main" java.lang.RuntimeException: Missing character set id 170 not loaded at image build time at oracle.sql.CharacterSet.make(CharacterSet.java:121) at oracle.jdbc.driver.DBConversion.init(DBConversion.java:184) at oracle.jdbc.driver.DBConversion.(DBConversion.java:137) at oracle.jdbc.driver.T4CConnection.doCharSetNegotiation(T4CConnection.java:2607) at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:2176) at oracle.jdbc.driver.T4CCon nection.logon(T4CConnection.java:644) at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:1069) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:90) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:681) at oracle.jdbc.datasource.impl.OracleDataSource.getPhysicalConnection(OracleDataSource.java:569) at oracle.jdbc.datasource.impl.OracleDataSource.getConnection(OracleDataSource.java:355) at oracle.jdbc.datas ource.impl.OracleDataSource.getConnectionInternal(OracleDataSource.java:2014) at oracle.jdbc.datasource.impl.OracleDataSource.getConnection(OracleDataSource.java:330) at oracle.jdbc.datasource.impl.OracleDataSource.getConnection(OracleDataSource.java:291) at DataSourceSample.main(DataSourceSample.java:24)

DataSourceSample.java

/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.*/
import java.sql.SQLException;
import java.util.Properties;

import oracle.jdbc.pool.OracleDataSource;
import oracle.jdbc.OracleConnection;
import java.sql.DatabaseMetaData;

public class DataSourceSample {  
  final static String DB_URL= "jdbc:oracle:thin:@****:1525/****";
  final static String DB_USER = "****";
  final static String DB_PASSWORD = "****";

  public static void main(String args[]) throws SQLException {
    Properties info = new Properties();     
    info.put(OracleConnection.CONNECTION_PROPERTY_USER_NAME, DB_USER);
    info.put(OracleConnection.CONNECTION_PROPERTY_PASSWORD, DB_PASSWORD);          
    info.put(OracleConnection.CONNECTION_PROPERTY_DEFAULT_ROW_PREFETCH, "20");    

    OracleDataSource ods = new OracleDataSource();
    ods.setURL(DB_URL);    
    ods.setConnectionProperties(info);

    try (OracleConnection connection = (OracleConnection) ods.getConnection()) {
      DatabaseMetaData dbmd = connection.getMetaData();       
      System.out.println("Driver Name: " + dbmd.getDriverName());
      System.out.println("Driver Version: " + dbmd.getDriverVersion());
      System.out.println("Default Row Prefetch Value is: " + 
         connection.getDefaultRowPrefetch());
      System.out.println("Database Username is: " + connection.getUserName());
      System.out.println();
    }   
  }
}

I'm not 100% sure that it's the culprit, but here's the general idea about native image and charsets.

Native image doesn't include all possible charsets by default, you can configure it to do so by using the following option:

-H:+AddAllCharsets

Another possible option is to initialize the CharSet onject in a class that is configured to be initialized at build time of the native image. Then the charset object will be saved in the "image heap" and will be available at runtime.

Here's a sample application that illustrates this behavior: https://github.com/shelajev/workshop/tree/main/3

Of course it might be something different, but I think this should solve the problem you're experiencing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM