File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes BLOB truncated to 64MB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "BLOB truncated to 64MB" Watch "BLOB truncated to 64MB" New topic

BLOB truncated to 64MB

Manzar Zaidi
Ranch Hand

Joined: Oct 21, 2004
Posts: 43
I am attempting to save a file to a mySQL db from a servlet, the issue I face is that its truncating the files to a size of 65535 bytes everytime!
The code works properly with files with smaller soze, I tested upload and download with small file sizes.
No errors show up.

The code I am using is: (Just posting the relevant portion)

try {
pstmt = dbConn.prepareStatement("INSERT INTO files VALUES( ?, ? )" ); }
catch (SQLException sqle) {System.out.println("While making prepard stat
Caught ex="+sqle);}
pstmt.setString( 1, "FileName");
File imageFile = new File("pathToFileToBeUploaded.ext");
InputStream is = new FileInputStream(imageFile);
pstmt.setBinaryStream( 2, is, 999000); // Tried using different values here, no go
}catch (SQLException sqle)
{System.out.println("Caught ex="+sqle);

Could you advise me about what what can it be ?

SCJP 1.2, SCWCD 1.4.<br />What goes around comes around ... with ver 1.1
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
I guess JDBC forum would be a better place.

Anyhow, may be its mySql issue. Try Oracle or something similar(reliable and tested).
Lewin Chan
Ranch Hand

Joined: Oct 10, 2001
Posts: 214
Change the column to be MEDIUMBLOB

If you read the mysql docs BLOBs are specified to be 64k or less, MEDIUMBLOB is 2^24 bytes max (16Mb?) , LONGBLOB is 2^32 bytes max. @see

Adeel, while oracle may be reliable and tested (in your opinion, I don't have one), it generally also costs $$$, which might not be so suitable on this occasion. Mind you, LAMP style applications wouldn't be quite so popular if mysql wasn't considered reliable and tested so perhaps I do have an opinion.

I have no java certifications. This makes me a bad programmer. Ignore my post.
I agree. Here's the link:
subject: BLOB truncated to 64MB