ArrayList temp2 = new ArrayList();
我用 long 填充这个数组列表。
当我尝试将其插入 postgresql 时,我使用以下内容:
更新 pb1plnitm SETparents_pb1plnitm_unid = ARRAY[?] WHERE pb1plnitm_unid = ?", temp2, xmlForm.getFieldValueLong("uniqueid"));
使用 JDBC 模板。但是当我尝试运行此代码时,它在“ARRAY[?]”上给出错误。但如果 temp2 是单个数字,例如:1253214,则它可以工作。有人有想法吗?
我的错误是:
PreparedStatementCallback; bad SQL grammar [UPDATE pb1plnitm SET parents_pb1plnitm_unid = ARRAY[?] WHERE pb1plnitm_unid = ?]; nested exception is org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of [Ljava.lang.Long;. Use setObject() with an explicit Types value to specify the type to use.
最佳答案
如错误描述中所述,使用setObject()
方法
例如:
Array sqlArray = conn.createArrayOf("text", anyArray);
pstmt.setArray(1, sqlArray);
pstmt.executeUpdate();
关于java - 尝试插入 Long 数组时 Postgresql 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40375013/