I'm trying to execute a simple JDBC query against a Snowflake database, just to test the connectivity.
In my pom,
<dependencies>
<!-- https://mvnrepository.com/artifact/net.snowflake/snowflake-jdbc -->
<dependency>
<groupId>net.snowflake</groupId>
<artifactId>snowflake-jdbc</artifactId>
<version>3.15.0</version>
</dependency>
</dependencies>
I can successfully create a connection. My credentials are accepted as valid. However, even the simplest of queries results in an NPE thrown from within the net.snowflake.client
package.
val connection = DriverManager.getConnection(dbUrl, connectionProperties)
connection.prepareStatement("select 1")
.executeQuery()
.getInt(1)
Executing this results in the following error:
java.lang.NullPointerException: Cannot invoke "java.util.List.size()" because "this.currentConverters" is null at net.snowflake.client.jdbc.ArrowResultChunk$ArrowChunkIterator.getCurrentConverter(ArrowResultChunk.java:462) at net.snowflake.client.core.SFArrowResultSet.getInt(SFArrowResultSet.java:408) at net.snowflake.client.jdbc.SnowflakeResultSetV1.getInt(SnowflakeResultSetV1.java:192)
I'm dumbfounded that my "hello world" program resulted in an internal error in the library.
Surely there must be a way to solve this? Am I missing some other dependency, maybe?
Silly me, I forgot to call next
before using the result set.
I took a look at the ArrowResultChunk
code, and it turns out that currentConverters
is not initialized until ResultSet::next
is called.
So, here is a working version of the above code (with auto closing resources too)
connection.prepareStatement("select 1").use { ps ->
ps.executeQuery().use { rs ->
rs.next()
rs.getInt(1)
}
}