Skip to content
Advertisement

Cannot use setArray JDBC (integer) with H2 Database

I want to put an array of integers in my jdbc query with H2 database.

JavaScript

But doest not work, I am getting this exception : org.h2.jdbc.JdbcSQLException: Data conversion error converting “(1,2,3)”; SQL statement:

I am using H2 database. Can you help me please?

Advertisement

Answer

Using my JDBC utilities to work with JDBC IN array parameters easily:

1. If Maven, add the below dependency into your pom.xml

JavaScript

2. If no maven, download this jar file

3. Fix your code ( Works all DBMS guaranteed )

JavaScript

4. Named parameters / Null parameters

JavaScript

5. Some Notes

  • Parameter name supported. No more ? in your query
  • Parameter in Sql need to start with : (Like JPA parameters)
  • IN Array parameter in Sql must be in this syntax IN :param_name
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement