Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BLOB truncated to 64MB

 
Manzar Zaidi
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);}
try{
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
pstmt.executeUpdate();
uploadSucess=true;
}catch (SQLException sqle)
{System.out.println("Caught ex="+sqle);
}

Could you advise me about what what can it be ?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 http://dev.mysql.com/doc/mysql/en/storage-requirements.html

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic