Sti*_*ing 3 sql arrays postgresql jdbc
我试图将一个真正的数组插入postgresql数组:
表定义是:
String sqlTable = "CREATE TABLE IF NOT EXISTS ccmBlock"
+ " sampleId INTEGER,"
+ " block REAL[])";
Run Code Online (Sandbox Code Playgroud)
插入是:
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);
Run Code Online (Sandbox Code Playgroud)
我收到一条消息:org.postgresql.util.PSQLException:无法找到提供的名称为real的服务器数组类型.
但是在他们的文档页面上:http: //www.postgresql.org/docs/8.4/static/datatype-numeric.html
表8-2.数字类型
名称StorageSize描述范围
真正的 4字节变精度,不精确的6位十进制数精度
Postgresql JDBC驱动程序对类型的命名有自己的想法.您可以在TypeInfoCache类中查找它们.
在你的情况下,正确的名称是float4,所以该行将:
Object[] theArray = {.11f, .22f, .33f};
Array a = theConnection.createArrayOf("float4", theArray);
Run Code Online (Sandbox Code Playgroud)
Props转到@JBNizet,在类似的问题中建议这个注册表.
| 归档时间: |
|
| 查看次数: |
2638 次 |
| 最近记录: |