Java PostgresJDBC8.4和9之间关于ByteArray的变化是什么?
我正在用PostgreSQL 9.0运行MacOSX 10.6。我编写了一个简单的Java应用程序,在bytea字段中插入一个图像,然后查询同一字段以检查它 下表:Java PostgresJDBC8.4和9之间关于ByteArray的变化是什么?,java,postgresql,jdbc,Java,Postgresql,Jdbc,我正在用PostgreSQL 9.0运行MacOSX 10.6。我编写了一个简单的Java应用程序,在bytea字段中插入一个图像,然后查询同一字段以检查它 下表: CREATE TABLE test.test_table ( id integer NOT NULL, image bytea, CONSTRAINT test_table_pkey PRIMARY KEY (id) ); 该计划类似于: //insert the file PreparedState
CREATE TABLE test.test_table
(
id integer NOT NULL,
image bytea,
CONSTRAINT test_table_pkey PRIMARY KEY (id)
);
该计划类似于:
//insert the file
PreparedStatement ps = connection.prepareStatement("INSERT INTO test.test_table( id, image ) VALUES (?, ?);");
byte[] bytesFromFile = readFile("img/test1.bmp");
ps.setInt(1, 1);
ps.setBytes(2, bytesFromFile);
ps.execute();
ps.close();
PreparedStatement stmt = connection.prepareStatement("Select id,image from test.test_table");
ResultSet rs = stmt.executeQuery();
//Get the file from the BD and save it to the FS
while (rs.next()) {
String id = rs.getString(1);
InputStream imageStream = rs.getBinaryStream(2);
String imageName = OUTPUT_DIR + "/" + id + ".bmp";
FileOutputStream f = new FileOutputStream(imageName);
byte buff[] = new byte[1024];
int l;
while ((l = imageStream.read(buff)) > 0) {
f.write(buff, 0, l);
}
f.close();
System.out.println("CREATED : " + imageName);// + " size " +
}
以下是事实
我可以升级驱动程序,没问题。我担心的是:PostgreSQL 9不再支持的通信协议内部发生了什么变化?字节数组的编码(服务器发送它们的方式)已从8.4更改为9.0: 请参阅发行说明:
以及配置设置的详细说明:
+1谢谢你的回答!总之,驱动程序8.4希望数据处于转义模式,但PostgreSQL 9以十六进制模式发送数据。