db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kristian Waagan <Kristian.Waa...@Sun.COM>
Subject Re: master and slave are not in synch for replicated database
Date Mon, 13 Apr 2009 13:24:01 GMT
Philip Rossomando wrote:
> I have long been a silent member of this group but I now need help.
> The following code was written by me to insert a Blob into the DB.
>
> 	public void insertImage(BufferedImage image) {
> 		try {
> 			byte[] bytes = this.getBytes(image);
> 			System.out.println("Bytes given to archive: " +
> bytes.length);
> 			String sql = "UPDATE TEST SET IMAGE = ? WHERE ID =
> ?";
> 			PreparedStatement ps = conn_.prepareStatement(sql);
> 			// ps.setBinaryStream(1, new
> ByteArrayInputStream(bytes),
> 			//			bytes.length);
> 			ps.setBlob(1, new ByteArrayInputStream(bytes),
> bytes.length);
> 			ps.setInt(2, 1);
> 			System.out.println("Rows written: " +
> ps.executeUpdate());
> 			conn_.commit();
> 			ps.close();
> 			System.out.println("Image Stored!");
> 		} catch (SQLException e) {
> 			printSQLError(e);
> 		} catch (Exception exc) { // process error
> 			System.err.println("process error" + exc);
> 		}
> 		return;
> 	}
>
> I converted a buffered image into an array bytes and then use setBlob() to
> prepare
> To write the blob to the db. Doing a bytes.length I get 372076. When I do my
>
> executeUpdate() I get back 0 indicating nothing was written. Sure enough, in
> IJ I
> see nothing was written Why? I tried setBinaryStream() changing Blob to
> LONVARBINARY.
> That didn't work either? Again Why.
>   

Hello Philip,

My guess would be that there is no existing row with the specified id in 
the database. In that case, you have to use an INSERT statement instead 
of UPDATE.


Regards,
-- 
Kristian

> Please help me here. Thank you.
>
> Phil Rossomando
>
> -----Original Message-----
> From: Brian Spindler [mailto:bspindler@netuitive.com] 
> Sent: Tuesday, April 07, 2009 10:23 PM
> To: Derby Discussion
> Subject: RE: master and slave are not in synch for replicated database
>   
[ snip ]

Mime
View raw message