0

While my issue sounds same to this one Snowflake JDBC driver internal error: Fail to retrieve row count for first arrow chunk: null -- only occurs on SELECT statements, but actually it is not.

I am able to connect to Snowflake data warehouse from java:

public static Connection getConnection()
        throws SQLException
{
    String user = Optional.ofNullable(System.getenv("USER"))
            .or(() -> Optional.ofNullable(System.getenv("USERNAME")))
            .orElseThrow();
    try
    {
        Class.forName("net.snowflake.client.jdbc.SnowflakeDriver");
    }
    catch (ClassNotFoundException ex)
    {
        System.err.println("Driver not found");
    }
    // build connection properties
    Properties properties = new Properties();
    properties.put("authenticator", "xxx");
    properties.put("user", user);    
    String connStr = Optional.ofNullable(System.getenv("SF_JDBC_CONNECT_STRING")).orElse("jdbc:snowflake://xxx.xxx.com");
    return DriverManager.getConnection(connStr, properties);
}

but when I try to run a very simple select statement from below code:

   try {
        Connection conn = Helper.getConnection();
        Statement sqlStm = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet sqlOutput = sqlStm.executeQuery("select getdate();");
        while (sqlOutput.next()) {
            System.out.println(sqlOutput.getInt(1));
        }
    }
    catch (SQLException e){
        e.printStackTrace();
    }

I am getting below error:

net.snowflake.client.jdbc.SnowflakeSQLLoggedException: JDBC driver internal error: Fail to retrieve row count for first arrow chunk: sun.misc.Unsafe or java.nio.DirectByteBuffer.<init>(long, int) not available.
at net.snowflake.client.jdbc.SnowflakeResultSetSerializableV1.setFirstChunkRowCountForArrow(SnowflakeResultSetSerializableV1.java:1066)
at net.snowflake.client.jdbc.SnowflakeResultSetSerializableV1.create(SnowflakeResultSetSerializableV1.java:550)
at net.snowflake.client.jdbc.SnowflakeResultSetSerializableV1.create(SnowflakeResultSetSerializableV1.java:467)
at net.snowflake.client.core.SFResultSetFactory.getResultSet(SFResultSetFactory.java:29)
at net.snowflake.client.core.SFStatement.executeQueryInternal(SFStatement.java:220)
at net.snowflake.client.core.SFStatement.executeQuery(SFStatement.java:135)
at net.snowflake.client.core.SFStatement.execute(SFStatement.java:781)
at net.snowflake.client.core.SFStatement.execute(SFStatement.java:677)
at net.snowflake.client.jdbc.SnowflakeStatementV1.executeQueryInternal(SnowflakeStatementV1.java:238)
at net.snowflake.client.jdbc.SnowflakeStatementV1.executeQuery(SnowflakeStatementV1.java:133)
at com.marqeta.Main.main(Main.java:42)

I found on github that people had the same issue on this thread: https://github.com/snowflakedb/snowflake-jdbc/issues/484. I had set the VM options as per below, but still have the same error, did I set the VM options wrongly or what could be the issues please. enter image description here

Andie
  • 23
  • 8

1 Answers1

1

I added --add-opens java.base/java.nio=ALL-UNNAMED as VM argument for the tests and they are passing.enter image description here

Please refer to this comment. Also, there is a good explanation of why this is happening. Passing the VM argument should be considered as a temporary solution.

Zafar
  • 1,111
  • 2
  • 11
  • 23
  • Thanks heaps @Zafar, really appreciate your help. While it did work in IntelliJ when I setup in VM options, but when I run the build artifacts (the jar file) from terminal, I am essentially getting the same error: net.snowflake.client.jdbc.SnowflakeSQLLoggedException: JDBC driver internal error: Fail to retrieve row count for first arrow chunk: sun.misc.Unsafe or java.nio.DirectByteBuffer.(long, int) not available. Wondering what setting do I need to run jar successfully. This is how I run the jar: java -cp com.xxx.Main – Andie Jan 14 '22 at 04:38
  • got it worked, apparently I have to add those options when run the jar file, like this: java -cp xxx.jar --add-opens java.base/java.nio=ALL-UNNAMED com.xxx.Main – Andie Jan 14 '22 at 06:14