postgres jdbc 8.4 和 9 之间关于字节数组有什么变化?

发布于 2024-10-14 21:54:35 字数 1756 浏览 0 评论 0原文

我正在运行 Mac OSX 10.6 和 PostgreSQL 9.0。我编写了一个简单的 Java 应用程序,它将图像插入到 bytea 字段中,然后查询同一字段来检查它。

表格:

 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 " +

            }

以下是事实。

  1. 使用驱动程序 postgresql-9.0-801.jdbc4.jar 就可以了 完美地工作在 PostgreSQL 8.4 和 PostgreSQL 9

  2. 使用驱动程序 8.4-701.jdbc4 有效 仅在 PostgreSQL 8.4 中。

  3. 使用 带有 PostgreSQL 的驱动程序 8.4-701.jdbc4 9 不行。提取的文件不同。 md5表明数据库中的内容与原始文件相同。因此,我的假设是问题出在提取文件期间。

我可以升级驱动程序,没问题。我关心的是:PostgreSQL 9 不再支持的通信协议内部发生了什么变化?

I'm running Mac OSX 10.6 with PostgreSQL 9.0. I wrote a simple Java application that insert an image in a bytea field and then query the same field to check it.

The table:

 CREATE TABLE test.test_table
   (
   id integer NOT NULL,
  image bytea,
  CONSTRAINT test_table_pkey PRIMARY KEY (id)
);

The program is something like:

//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 " +

            }

Here are the facts.

  1. Using the driver
    postgresql-9.0-801.jdbc4.jar it
    works perfectly both in
    PostgreSQL 8.4 and with PostgreSQL 9

  2. Using the driver 8.4-701.jdbc4 works
    only in PostgreSQL 8.4 .

  3. Using the
    driver 8.4-701.jdbc4 with PostgreSQL
    9 doesn't work. The extracted file is different. An md5 shows that the content in the database is equals to the original file. Therefore, my assumption is that the problem is during the extraction of the file.

I can upgrade the driver, thats no problem. My concern is: what has changed inside the communication protocol that is no longer supported in PostgreSQL 9 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾铮苏瑾 2024-10-21 21:54:35

字节数组的编码(服务器发送它们的方式)已从 8.4 更改为 9.0:

请参阅发行说明:
http://www.postgresql.org/docs/9.0 /static/release-9-0.html#AEN99255

以及配置设置的详细说明:
http://www.postgresql.org /docs/9.0/static/runtime-config-client.html#GUC-BYTEA-OUTPUT

The encoding of byte arrays (the way the server sends them) has been changed from 8.4 to 9.0:

See the release notes:
http://www.postgresql.org/docs/9.0/static/release-9-0.html#AEN99255

and the description of the configuration setting for details:
http://www.postgresql.org/docs/9.0/static/runtime-config-client.html#GUC-BYTEA-OUTPUT

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文