This content has been marked as final. Show 15 replies
Do what? Use setBytes or setBlob of PreparedStatement?
InputStream is=new FileInputStream("1.bmp");
- - - - - -
- - - - - -
You could also stick to one thread ...
I followed the suggestion of haris_beginner:
java.sql.PreparedStatement ps = conn.prepareStatement("insert into > table (column1) values( "data" );" );The database is made up of two columns: column1, whose type is 'Varchar' and column2, whose type is MediumBlob.
InputStream inp = new ByteArrayInputStream(data);
ps.setBinaryStream( 1, inp, inp.available());// "1"=idex of column2
but when I run the program occurs this error:
java.sql.SQLException: No parameters defined during prepareCall()
Use single quotes around "data" instead of double quotes.
Quotes are not the problem!
Well if you are using the statement exactly as displayed above
then they most certainly will be.
java.sql.PreparedStatement ps = conn.prepareStatement("insert into > table (column1) values( "data" );" );
Sorry, a typing error: I meant:
java.sql.PreparedStatement ps = conn.prepareStatement("insert into table (column1) values( "data" );" );
Which is the MySQL syntax to insert a MediumBlob field?
To insert Blob data (an array of byte called "data") I tryed the following code; the blob colomn is called "column2" and the table(called "myTable") has only another column ("column1"), a column of String:
InputStream inp = new ByteArrayInputStream(data);The problem is that I have the following error:
stmt.executeUpdate("insert into myTable (column1)
values( ' value1' ); " );
ResultSet res = stmt.executeQuery("select column2 from myTable");
Exception in thread "AWT-EventQueue-0" java.lang.AbstractMethodError: >com.mysql.jdbc.ResultSet.updateBlob(Ljava/lang/String;Ljava/io/InputStream;)V
Sounds like BLOBs are perhaps not fully supported in MySQL, so you might need a more full-fledged database.
Then the driver doesn't support that method. You will have to go back and fix the PreparedStatement, which was never correct in the first place. (As was pointed out to you.)
My guess is that it should look something like this:
conn.prepareStatement("insert into table (column1) values( ? )")
I'm sure MySQL can have blobs. I think the problem is how you're trying to
insert the data. Have you tried with an SQL INSERT in a PreparedStatement?
Update methods of ResultSet are poorly supported, in general.
Yes, I tryed with an Insert directly from the PreparedStatement, but the data inserted using this method aren't the ones I want: they seems like the address of the memory location of the InputStream.