我试图将一个真实的数组插入到 postgresql 数组中:
该表的定义是:
String sqlTable = "CREATE TABLE IF NOT EXISTS ccmBlock"
+ " sampleId INTEGER,"
+ " block REAL[])";
插入内容是:
String sqlInsert = "INSERT INTO ccmBlock"
+ "(sampleId, block) VALUES"
+ "(?,?)";
PreparedStatement preparedStatement = theConnection.prepareStatement(sqlInsert);
preparedStatement.setInt(1, 1);
Object[] theArray = {.11f, .22f, .33f};
Array a = theConnection.createArrayOf("real", theArray);
preparedStatement.setArray(2, a);
我收到一条消息:
org.postgresql.util.PSQLException:无法找到提供的名称真实的服务器数组类型。
但在他们的文档页面上:http://www.postgresql.org/docs/8.4/static/datatype-numeric.html http://www.postgresql.org/docs/8.4/static/datatype-numeric.html
表 8-2。数字类型
名称 存储大小 说明 范围
real4 字节精度可变,不精确的 6 位小数精度
Postgresql JDBC 驱动程序对于类型的命名有自己的想法。您可以在以下位置查找它们类型信息缓存类 http://grepcode.com/file/repo1.maven.org/maven2/postgresql/postgresql/9.1-901.jdbc4/org/postgresql/jdbc2/TypeInfoCache.java/.
在你的情况下,正确的名称是float4
,所以该行将是:
Object[] theArray = {.11f, .22f, .33f};
Array a = theConnection.createArrayOf("float4", theArray);
Props 转到 @JBNizet 在一个建议中使用此注册表类似的问题 https://stackoverflow.com/q/7931654/785663.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)