简体   繁体   English

如何使用java从Oracle检索Long

[英]How to retrieve a Long from Oracle using java

I have a database where a Long datatype has an image stored in it, I want to retrieve it and write it to an image file,我有一个数据库,其中 Long 数据类型存储了一个图像,我想检索它并将其写入图像文件,

I tried using getBytes method and write a file using for and it return as corrupt image,我尝试使用 getBytes 方法并使用 for 编写一个文件,它作为损坏的图像返回,

I also tried using getBinarystream and write using fos I wrote it in an image file I get same corrupt error.我还尝试使用 getBinarystream 并使用 fos 写入我将其写入图像文件中,但出现相同的损坏错误。

Code:代码:

InputStream is = RS.getBinaryStream(1);
FileOutputStream fos = new FileOutputStream ("image.bmp");
Int c;
While((c=is.read())!=-1)
{
fos.write(c);
}
fos.close;

To store binary data you should use LONG_RAW or a BLOB.要存储二进制数据,您应该使用 LONG_RAW 或 BLOB。 The type LONG is for character based (text) data. LONG 类型用于基于字符的(文本)数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM