The moose likes JDBC and Relational Databases and the fly likes JDBC updates using result sets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "JDBC updates using result sets" Watch "JDBC updates using result sets" New topic

JDBC updates using result sets

Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
Hi folks,

I am trying to update a blob field in a MySQL database using updatable result sets. Should be simple. I have no problem updating my blob using prepared statements or updating other fields on the table. The problem is with the blob! I am going crazy trying to figure this out. Would some smart soul please take a look and tell me what's wrong?

regards and thanks,

Here is the table:

mysql> show columns from titles;
| Field | Type | Null | Key | Default | Extra |
| TitleId | int(11) | | PRI | 0 | |
| Title | varchar(50) | YES | | NULL | |
| Year | int(11) | YES | | NULL | |
| Price | float | YES | | NULL | |
| URL | varchar(50) | YES | | NULL | |
| Image | blob | YES | | NULL | |
| ByteLength | int(5) | YES | | NULL | |
7 rows in set (0.00 sec)

Here is the SQL query:

SELECT TitleID, Title, Image, ByteLength from Titles WHERE TitleID = 11

which should create a single entry in the result set.

Here is the code:

And here is the output from the console, which shows that even though I have retrieved the record, the getBlob() method does not retrieve a handle to the blob!

C:\Java\JDBC\classes>java com.ingasimn.EV010 11
SELECT TitleID, Title, Image, ByteLength from Titles WHERE TitleID = 11
connection established
got record
number of rows in dbRS 1
Title : The Sound of Music
at com.ingasimn.EV010.actionPerformed(
at javax.swing.AbstractButton.fireActionPerformed(
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.j
at javax.swing.DefaultButtonModel.fireActionPerformed(

at javax.swing.DefaultButtonModel.setPressed(
at javax.swing.AbstractButton.doClick(
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(
at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMen
at java.awt.Component.processMouseEvent(
at java.awt.Component.processEvent(
at java.awt.Container.processEvent(
at java.awt.Component.dispatchEventImpl(
at java.awt.Container.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.LightweightDispatcher.retargetMouseEvent(
at java.awt.LightweightDispatcher.processMouseEvent(
at java.awt.LightweightDispatcher.dispatchEvent(
at java.awt.Container.dispatchEventImpl(
at java.awt.Window.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.EventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(
at java.awt.EventDispatchThread.pumpEventsForHierarchy(
at java.awt.EventDispatchThread.pumpEvents(
at java.awt.EventDispatchThread.pumpEvents(
Connection Closed
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1323

where you initialize this Object "blog"?

try this

make sure the package is already imported in this file. java.sql.Blob;

hope it helps..

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
Just in case you had not thought of it, have you tried running that command from the MySql command line? Perhaps the record has not been populated as you think it has.

You may also want to consider catching the SQLException. It may tell you something else. As far as I can tell from the information that you have provided, Title has a value, but Image does not, hence the null pointer error. Perhaps there is an error where you insert your blob?

But I am sure that you already figured that out.
Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
Thanks guys. I tried both suggestions. I have managed to get the thing working but I had to use Streams. Shame really! If anyone can demonstrate how to use Blobs I will be very interested!

I agree. Here's the link:
subject: JDBC updates using result sets
It's not a secret anymore!