问题描述
我试图插入表中的一个数组,但我需要在列表转换为SQL数组类型。我使用了连接#createArrayOf()
方法,但我得到一个例外。
我需要通过一个类型的名字,但我不知道这是什么,我总是得到一个异常。该数组是从VARCHAR。
我该如何解决这个插入阵列?
的code
对象[]数组=新对象[token.getCategories()大小()];
。阵= token.getCategories()的toArray();
pstmTokenInsert.setArray(1,conn.createArrayOf(VARCHAR,数组));
堆栈跟踪
org.postgresql.util.PSQLException:找不到数组类型,数据类型为VARCHAR
在org.postgresql.jdbc4.AbstractJdbc4Connection.createArrayOf(AbstractJdbc4Connection.java:73)
在org.postgresql.jdbc4.Jdbc4Connection.createArrayOf(Jdbc4Connection.java:21)
在org.apache.commons.dbcp.DelegatingConnection.createArrayOf(DelegatingConnection.java:560)
在br.ifsp.da.data.TokenDAO.insertTokens(TokenDAO.java:37)
在br.ifsp.da.data.ProcessedPageInserter.loopInsertion(ProcessedPageInserter.java:44)
在br.ifsp.da.data.ProcessedPageInserter.call(ProcessedPageInserter.java:27)
在java.util.concurrent.FutureTask中$ Sync.innerRun(FutureTask.java:334)
在java.util.concurrent.FutureTask.run(FutureTask.java:166)
在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:603)
在java.lang.Thread.run(Thread.java:722)
使用VARCHAR而不是VARCHAR。见<一href=\"http://grep$c$c.com/file/repo1.maven.org/maven2/postgresql/postgresql/9.0-801.jdbc4/org/postgresql/jdbc2/TypeInfoCache.java#TypeInfoCache.0types\">http://grep$c$c.com/file/repo1.maven.org/maven2/postgresql/postgresql/9.0-801.jdbc4/org/postgresql/jdbc2/TypeInfoCache.java#TypeInfoCache.0types
I'm trying to insert an array in a table, but I need to convert the list to the SQL Array type. I'm using the Connection#createArrayOf()
method, but I'm getting an exception.
I need to pass a type name, but I don't know what is this and I always get an exception. The array is from VARCHAR.
How I solve this to insert the array?
The code
Object[] array = new Object[token.getCategories().size()];
array = token.getCategories().toArray();
pstmTokenInsert.setArray(1, conn.createArrayOf("VARCHAR", array));
The stacktrace
org.postgresql.util.PSQLException: Could not find array type for data type VARCHAR
at org.postgresql.jdbc4.AbstractJdbc4Connection.createArrayOf(AbstractJdbc4Connection.java:73)
at org.postgresql.jdbc4.Jdbc4Connection.createArrayOf(Jdbc4Connection.java:21)
at org.apache.commons.dbcp.DelegatingConnection.createArrayOf(DelegatingConnection.java:560)
at br.ifsp.da.data.TokenDAO.insertTokens(TokenDAO.java:37)
at br.ifsp.da.data.ProcessedPageInserter.loopInsertion(ProcessedPageInserter.java:44)
at br.ifsp.da.data.ProcessedPageInserter.call(ProcessedPageInserter.java:27)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Use "varchar" instead of "VARCHAR". See http://grepcode.com/file/repo1.maven.org/maven2/postgresql/postgresql/9.0-801.jdbc4/org/postgresql/jdbc2/TypeInfoCache.java#TypeInfoCache.0types
这篇关于如何创建Java列表一个SQL数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!