从数据库保存/检索二进制数据
我在 tomcat 6.0.32 x64 中部署了一个 Web 应用程序,它使用 Hibernate 3.0 连接 Postgres 9.0 x64 数据库。
该应用程序在数据库中保存一个二进制字段,当我找到它时,它是不同的。
二进制保存: [-82, 120, 71, 23, -88, 67, 36, 30, 57, -72, 42, 29, -64, 93, -8, -103, -63, 124, 66, 20]
二进制获得: [-67, 55, 56, 52, 55, 49, 55, 97, 56, 52, 51, 50, 52, 49, 101, 51, 57, 98, 56, 50, 97, 49, 100, 99, 48、53、100、102、 56, 57, 57, 99, 49, 55, 99, 52, 50, 49, 52]
谢谢
I have a web app deployed in tomcat 6.0.32 x64 and it's using Hibernate 3.0 to connect a Postgres 9.0 x64 database.
The app saves a binary field in the database and when I find it, it is different.
Binary Saved:
[-82, 120, 71, 23, -88, 67, 36, 30, 57, -72, 42, 29, -64, 93, -8, -103, -63, 124, 66, 20]
Binary Obtained:
[-67, 55, 56, 52, 55, 49, 55, 97, 56, 52, 51, 50, 52, 49, 101, 51, 57, 98, 56, 50, 97, 49, 100, 99, 48, 53, 100, 102, 56, 57, 57, 99, 49, 55, 99, 52, 50, 49, 52]
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查您的 postgres jdbc 驱动程序版本。它至少应该与您的数据库服务器一样新,因此您需要 9.0 或更高版本的驱动程序。
我相信 bytea 线格式在 9.0 中发生了变化,如果您有旧的驱动程序,这可以解释这个问题。
Check your postgres jdbc driver version. It should be at least as recent as your DB server, so you need a 9.0 driver or better.
I believe the bytea wire format changed in 9.0, which could explain this problem if you have an old driver.
你没有提供足够的细节,但我会冒险猜测在某些时候你正在将字节转换为字符(你的输出看起来大约是输入的两倍,java字符是2个字节)。字节!= 字符。
否则,可能与流的错误使用有关。
You don't provide enough details, but i'm going to go out on a limb and guess that at some point you are translating bytes to characters (your output looks about twice as long as your input, java characters are 2 bytes). bytes != chars.
otherwise, it could be something related to incorrect usage of streams.