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.