Re: com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError



David
When your program reaches the call to ResultSet.updateBlob at line 52,
the JVM attempts to call the method updateBlob on a concrete
com.mysql.jdbc.UpdatableResultSet object. That method is apparently
abstract, and you get the mysterious AbstractMethodError.
So MySQL Connector/J doesn't implement any code for handling blobs
here. Makes the most sence to me. Forget about the nice blob interface
then.

Lew
to a string (and playignorant on charset headaches), but I couldn't get that to work...
(furthermore, it doesn't seem the right way to go).
It isn't, but byte[] would be all right.
You are very right there. I liked the Blob's because they work with
streams, but the following code below works! With byte[].


I'll just wrap it in an URL2Bytes utility class and all is done.
Thanks for all your tips! Ciao

public static void main(String[] args)
throws MalformedURLException,
IOException, SQLException {
// download photo to byte[]
URL fileurl = new URL(
"http://www.woonnet-haaglanden.nl/";
+ "library/fotos/18/12845.jpg");
int length = fileurl.openConnection()
.getContentLength();
byte[] bytebuf = new byte[length];
InputStream is = fileurl.openStream();
byte[] b = new byte[1];
for (int i = 0; is.read(b) > -1; i++) {
bytebuf[i] = b[0];
}

// write to DB
Connection con = null;
try {
Class
.forName(
"com.mysql.jdbc.Driver")
.newInstance();
con = DriverManager.getConnection(
"jdbc:mysql:///woonnet",
"root", "<A2Cc|4w");
} catch (InstantiationException e) {
e.printStackTrace();
System.exit(1);
} catch (IllegalAccessException e) {
e.printStackTrace();
System.exit(1);
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
PreparedStatement pstmt = con
.prepareStatement("INSERT INTO `image` "
+ "(`house_id`, `image`) "
+ "VALUES(4, ?)");
pstmt.setBytes(1, bytebuf);
pstmt.executeUpdate();

// read from DB
Statement readstmt = con
.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet resultset = readstmt
.executeQuery("SELECT * FROM `image` " //
+ "WHERE `house_id` = 4;");
resultset.first();
byte[] readbytes = resultset
.getBytes("image");
Image image = ImageIO
.read(new ByteArrayInputStream(
readbytes));

// Use a label to display the image
JFrame frame = new JFrame();
JLabel label = new JLabel(new ImageIcon(
image));
frame.getContentPane().add(label,
BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}

.