Re: com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- From: "pjvleeuwen@xxxxxxxxx" <pjvleeuwen@xxxxxxxxx>
- Date: Tue, 02 Oct 2007 18:29:57 -0000
Sorry for the late response, just back from diner.
Arne
What version of the MySQL JDBC driver are you using ?<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.3</version>
</dependency>
And MySQL monitor informed me that I have 5.0.26-community-nt...
Dt
Why do you have to use an updatable result set to store the blob? WhySince I wouldn't know the answer to that question I also tried the
can't you use an ordnary update statment?
following
PreparedStatement pstmt = con
.prepareStatement("INSERT INTO `image` (`house_id`,
`image`) "
+ "VALUES(1, ?)");
pstmt.setBlob(1, new URL( // <===============line 51
"http://www.woonnet-haaglanden.nl/library/fotos/
18/12845.jpg")
.openStream());
pstmt.executeUpdate();
Exception in thread "main" java.lang.AbstractMethodError:
com.mysql.jdbc.ServerPreparedStatement.setBlob(ILjava/io/
InputStream;)V
at nl.vanleeuwenwilmot.housing.search.woonnet.app.Test.main(Test.java:
51)
And if I try setObject like the following I get no error at 51, but a
null-pointer exception after reading it.
public static void main(String[] args) throws IOException,
SQLException {
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(1, ?)");
pstmt.setObject(1, new URL(
"http://www.woonnet-haaglanden.nl/library/fotos/
18/12845.jpg")
.openStream());
pstmt.executeUpdate();
Statement readstmt = null;
readstmt =
con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet resultset = readstmt.executeQuery("SELECT * FROM
`image` " //
+ "WHERE `house_id` = 1;");
resultset.first();
InputStream theimage =
resultset.getBlob("image").getBinaryStream();
Image image = ImageIO.read(theimage);
// Use a label to display the image
JFrame frame = new JFrame();
JLabel label = new JLabel(new ImageIcon(image)); // <=== line
69
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:161)
at nl.vanleeuwenwilmot.housing.search.woonnet.app.Test.main(Test.java:
69)
Further more I tried reading the inputstream to a string (and play
ignorant on charset headaches), but I couldn't get that to work...
(furthermore, it doesn't seem the right way to go).
*Any* suggestions are warmly welcome. I stay tuned..
(oh and off topic suggestions on coding like dt.'s are also welcome,
there's just a lot that I don't know...)
.
- Follow-Ups:
- References:
- com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- From: pjvleeuwen@xxxxxxxxx
- Re: com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- From: Dyreatnews
- com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- Prev by Date: Re: com.mysql.jdbc.UpdatableResultSet.updateBlob gives AbstractMethodError
- 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):
Relevant Pages
|