Home arrow static arrow Java Programming [Archive] - retrieve blob values from mySQL through JDBC
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - retrieve blob values from mySQL through JDBC
This topic has 1 reply on 1 page.

Posts:5
Registered: 7/18/04
retrieve blob values from mySQL through JDBC  
Jul 18, 2004 11:49 PM



 
Hi! I' m a new member in the forum and I need help at the point of the subject. My problem is as follows:
I have a database in mySQL and a table containing 2 fields[e.g. myTable(file_id, file_content)]. The data type of file_d is int and the data type of file_content is mediumblob.
I want to retrieve all values of the file_content field through a JAVA program. So I make a jdbc connection to the database (the driver I use is mySQL Connector/J). My string query is:
String sql2 = "SELECT FILE_CONTENT FROM myTable where FILE_ID="+fileIds) , where fileIds[] is a table containing the file_id field values. The code that follows is:

ResultSet rsContent = stat.executeQuery(sql2);

if (rsContent.first())
{
Blob fileContent = rsContent.getBlob("FILE_CONTENT");

// setup the streams
InputStream input = fileContent.getBinaryStream();

String inputTest = new String();
length = fileContent.length();

int ch = 0;
while ((ch=input.read()) != -1)
{
System.out.print((char) ch);
}

rsContent.close();

}

I see that the connection to the database is done, as I can see printed some of the file_content values from the database, but for some file_ids I get the following exception:

An exception has been intercepted

java.sql.SQLException: Error during query: Unexpected Exception: java.lang.NegativeArraySizeException message given: null

Nested Stack Trace:

** BEGIN NESTED EXCEPTION **

java.lang.NegativeArraySizeException

STACKTRACE:

java.lang.NegativeArraySizeException

at com.mysql.jdbc.ByteArrayBuffer.getBytes(ByteArrayBuffer.java:108)

at com.mysql.jdbc.ByteArrayBuffer.readLenByteArray(ByteArrayBuffer.java:240)

at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1273)

at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2180)

at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:406)

at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:1914)

at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1354)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1667)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2273)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2204)

at com.mysql.jdbc.Statement.executeQuery(Statement.java:1138)

at gr.eurocom.KiaSite.Search.convertToText.main(convertToText.java:147)


** END NESTED EXCEPTION **


at com.mysql.jdbc.Connection.execSQL(Connection.java:2323)

at com.mysql.jdbc.Connection.execSQL(Connection.java:2204)

at com.mysql.jdbc.Statement.executeQuery(Statement.java:1138)

at gr.eurocom.KiaSite.Search.convertToText.main(convertToText.java:147)

Process exited with exit code 0.

Can anybody help me????

 

Posts:6,750
Registered: 1/25/04
Re: retrieve blob values from mySQL through JDBC  
Jul 19, 2004 8:00 AM (reply 1 of 1)



 
Please format your code according to the [url http://forum.java.sun.com/features.jsp#Formatting]Formatting Help[/url] page. It will be much easier to read.
 
This topic has 1 reply on 1 page.