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



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? Why
can't you use an ordnary update statment?
Since I wouldn't know the answer to that question I also tried the
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...)

.



Relevant Pages

  • Re: executescalar()
    ... Any idea what exception you are getting? ... > I'm trying to get the row count from a table, in the fastest way (con ... > Dim NRows As Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Re: JDBC Timestamp comparison
    ... Connection con = null; ... Statement stmt = null; ... ResultSet resultSet = null; ...
    (comp.databases.oracle.server)
  • Re: The Mermen
    ... On Dec 19, 4:45 pm, the long con ... suppose it's not AAHS with Mermen, ... Ray is the possible exception. ... You live for this, eh David? ...
    (rec.music.gdead)
  • Re: Creating connection string (i think)
    ... You are missing a single line:) ... BTW, you should code your code in this way: ... using (SqlConnection con = new SqlConnection(conStr)) ... even in the presence of an exception. ...
    (microsoft.public.dotnet.languages.csharp)