Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question on using Blob and preparedStatement 1

Status
Not open for further replies.

zhanghong920

Programmer
Nov 15, 2002
27
US
Thanks for your help for my precious question. Now I'm using jdbc to save the resulting data from a service to a mysql database. The field is defined to be Blob because the data maybe very large and different in length. The code is as below:

PreparedStatement insertCommand;
insertCommand = connection.prepareStatement("insert into filter values('?', '?', '?')");
insertCommand.setString(3, metadataString);
/*metadataString is the large data string I want to save to the database, produced from baos.toString(), where baos is a ByteArrayOutputStream object. */

But it has the error when I run it:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at com.mysql.jdbc.PreparedStatement.set(Unknown Source)
at com.mysql.jdbc.PreparedStatement.setString(Unknown Source)
at ....

Anything wrong in my code? Thanks a lot,

zhanghong920
 
try replacing the insertCommand line with..

insertCommand = connection.prepareStatement("insert into filter values(?, ?, ?)");

i.e. drop the ' characters, these are only used if a string is in the values(), e.g.

insertCommand = connection.prepareStatement("insert into filter values('abc', 'def', 'ghi')");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top