Re: com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- From: "pjvleeuwen@xxxxxxxxx" <pjvleeuwen@xxxxxxxxx>
- Date: Wed, 03 Oct 2007 12:06:50 -0000
David
When your program reaches the call to ResultSet.updateBlob at line 52,So MySQL Connector/J doesn't implement any code for handling blobs
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.
here. Makes the most sence to me. Forget about the nice blob interface
then.
Lew
You are very right there. I liked the Blob's because they work withto a string (and playignorant on charset headaches), but I couldn't get that to work...It isn't, but byte[] would be all right.
(furthermore, it doesn't seem the right way to go).
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);
}
.
- Follow-Ups:
- References:
- com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- From: pjvleeuwen@xxxxxxxxx
- Re: com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- From: David Harper
- Re: com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- From: pjvleeuwen@xxxxxxxxx
- Re: com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- From: David Harper
- com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- Prev by Date: Searching CLOBs through Hibernate
- Next by Date: Re: com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- Previous by thread: Re: com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- Next by thread: Re: com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- Index(es):