Java 将参数绑定为 PostgreSQL 数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18658107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Binding parameter as PostgreSQL array
提问by Ree
I'm trying to bind a prepared statement parameter which is a "multidimensional" PostgreSQL array. Here's an array example (column type is numeric[]
):
我正在尝试绑定一个准备好的语句参数,它是一个“多维”PostgreSQL 数组。这是一个数组示例(列类型为numeric[]
):
{{1,10},{2,20}}
How do I bind a value like that using a prepared statement? I tried:
如何使用准备好的语句绑定这样的值?我试过:
stmt.setObject(1, "{{1,10},{2,20}}", Types.ARRAY);
It didn't work:
它没有用:
Cannot cast an instance of java.lang.String to type Types.ARRAY
无法将 java.lang.String 的实例转换为 Types.ARRAY
Any ideas?
有任何想法吗?
采纳答案by Roman Pekar
Try something like this (untested):
尝试这样的事情(未经测试):
------------------ your connection
V
Array inArray = conn.createArrayOf("integer", new Integer[][] {{1,10},{2,20}});
stmt.setArray(1, inArray);
Links:
链接: