I'm getting a very strange results all of the sudden when dealing with BLOBs
in a mysql 3.23.32 on a Solaris 7 (SPARC) machine (inserts/deletes handled
with the JDBC driver from http://mmmysql.sourceforge.net/)
If I do the following:
1) Create a BDB table with a blob column:
CREATE TABLE test4(
id INTEGER not null PRIMARY KEY,
ablob BLOB null
) TYPE=BDB;
2) Insert a particular blob into that column (I'm storing XSLT stylesheets
in the real table, most of them work fine but one in particular is all of
the sudden causing problems):
---code snip---
String fn="badblob.txt"; // Filename of the blob I'm loading that
causes problems
FileInputStream style_fis=new FileInputStream(fn);
byte[] style_bytes=new byte[style_fis.available()];
style_fis.read(style_bytes);
String dQuery="delete from ttest4";
String iQuery="insert into ttest4(id,ablob) values(1,null);";
conn=cp.getConnection(); // Gets a JDBC connection from a pool I
keep elsewhere
Statement stmt=conn.createStatement();
stmt.executeUpdate(dQuery);
stmt.executeUpdate(iQuery);
stmt.close();
String uQuery="update test4 set ablob=? where id=1";
pstmt=conn.prepareStatement(uQuery);
pstmt.setBytes(1,style_bytes);
pstmt.execute();
pstmt.close();
cp.releaseConnection(conn);
---end code snip---
(I've modified this some, but basically my code will insert an empty row
then update it with the blob, this is to deal with some issues we've had
with other RDBMs' implementations of JDBC).
This seems to go just fine.
3) Retrieve that blob with the following code:
--code snip--
conn=cp.getConnection();
Statement stmt=conn.createStatement();
String query="select ablob from ttest4 where id=1";
ResultSet rs=stmt.executeQuery(query);
while(rs.next()) {
Blob b=rs.getBlob(1);
byte[] blobBytes=b.getBytes(0,(int)b.length());
System.out.println(new String(b));
}
--end code snip--
At this point my output ends up very garbled. The output usually starts off
with some very strange ASCII characters (seemingly binary data) with things
like filesystem names thrown in the mix... Then at some point parts of my
actual data (from the "badblob.txt" file in step 2) appears... Then the end
of it is usually overwritten with more strange ASCII characters.
In attempting to fix this problem, I dropped and recreated the entire
database a few times, restarted the server daemon, etc. I finally ended up
changing the table to TYPE=MyISAM and the problem went away. Unfortunately,
I need transaction support for this project.
I've been using this code, data, server version, bdb table, etc for a few
weeks now with no problems, but suddenly when regenerating the schema last
night this started to occur and is now happening regularly.
I'd like to blame this on the particular blob I'm inserting (badblob.txt)
but that doesn't seem to be the problem as it hasn't changed. My other
thought was a corrupt disk, but that doesn't seem likely... I'm open to any
suggestions as this problem seems potentially very serious.
Any help is greatly appreciated!
-Scott
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php