[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] swt Image with JDBC and sqlserver2000

I had create a table in sqlserver2000
create table test(pic image)
I write this to save a picture to database
Image image1 = new Image("tmp.jpg");
ImageLoader load = new ImageLoader();
load.data = new ImageData[1];
load.data[0] = image1.getImageData();
ByteArrayOutputStream output = new ByteArrayOutputStream();
load.save(output,SWT.IMAGE_JPEG);
ByteArrayInputStream input =
new ByteArrayInputStream(output.toByteArray());
PreparedStatement pstmt = con.prepareStatement("insert into test(pic)valuse(?)");
pstmt.setBinaryStream(1,input,input.available());
pstmt.executeUpdate();
it is save to database successfully.
but when read this picture from database it is failed.
I had write like this
Statement smt= con.createStatement();
ResultSet rst= smt.executeQuery("select pic from test");
if(rst.next())
InputStream input2=rst.getBinaryStream(1);
Image image2= new Image(null,input2);//it is failed
How can I read this picture from database
these are the exceptions
Exception in thread "main" org.eclipse.swt.SWTException: Unsupported or unrecognized format
at org.eclipse.swt.SWT.error(SWT.java:3374)
at org.eclipse.swt.SWT.error(SWT.java:3297)
at org.eclipse.swt.SWT.error(SWT.java:3268)
at org.eclipse.swt.internal.image.FileFormat.load(FileFormat.java:82)
at org.eclipse.swt.graphics.ImageLoader.load(ImageLoader.java:127)
at org.eclipse.swt.graphics.ImageDataLoader.load(ImageDataLoader.java:22)
at org.eclipse.swt.graphics.ImageData.<init>(ImageData.java:328)
at org.eclipse.swt.graphics.Image.<init>(Image.java:545)
Anyone can help me?
thanks