JdbcSQLNonTransientException: Unknown data type

97 views
Skip to first unread message

Jason Pickens

unread,
Aug 7, 2019, 10:51:25 PM8/7/19
to H2 Database
I have the following query:

connection.prepareStatement("SELECT * FROM (SELECT ?)")

This throws a "JdbcSQLNonTransientException: Unknown data type" exception as it needs to know the types of the temporary table.

This works:

"SELECT ?"

The parameter doesn't have a type in this case either.

Why does the prepared statement need to know the type of the temporary table? The lack of type information in the simple case doesn't appear to be a problem.

Is there any workaround? This is a total blocker to me using h2.

Evgenij Ryazanov

unread,
Aug 8, 2019, 12:52:26 AM8/8/19
to H2 Database
Hello.

H2 compiles your query immediately, so it needs to know the data types of some arguments.

The usual workaround is to wrap the parameter into CAST function. This function doesn't need to know the type of its argument.

SELECT * FROM (SELECT CAST(? AS INT))

Of course, you need to know the data types of such parameters.
Reply all
Reply to author
Forward
0 new messages