Upload PDF file to mysql BLOB by using java.sql.PreparedStatement without corruption

社会主义新天地 提交于 2019-12-04 11:52:40

Ahhh...After a little debugging I found the code that uploads is troublesome, and finally got the right way to do it.

Here is what I did...I'm posting it so that others with same problem can solve it

After Converting the java.io.File to java.io.FileInputStream

FileInputStream io = new FileInputStream(inFile);

Set the BLOB field using psmnt.setBinaryStream()

psmnt.setBinaryStream(3,  (InputStream)io,(int)inFile.length());
shivam

remove " java.sql.Blob blob = rs.getBlob("DOCUMENT"); "

and don't initialize length i.e instead of

int length = (int) blob.length();

just write

int length;

then it downloads file successfully .. enjoy :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!