x
login register about faq

problem in retrieving image from mysql

package cbir.imageAddition; import java.awt.Image; import java.awt.Toolkit; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.*; import javax.swing.JOptionPane; /** * * @author nidheesh */ public class ImageRetrieve { public ImageRetrieve() throws SQLException, IOException, ClassNotFoundException { Connection con = null; ResultSet rs = null; Statement st; String url = "jdbc:mysql://localhost:3306/"; String db = "image_db"; String driver = "com.mysql.jdbc.Driver"; String user = "root"; String pass = "root"; Class.forName(driver); con = DriverManager.getConnection(url + db, user, pass); //System.out.println("Connection url : "+url + db); st = con.createStatement(); String sql = "select * from image_details where id = 1"; rs = st.executeQuery(sql); String str = rs.getString("id"); System.out.println(str); InputStream stream = rs.getBinaryStream(1); System.out.println("4"); ByteArrayOutputStream output = new ByteArrayOutputStream(); int a1 = stream.read(); while (a1 >= 0) { output.write((char) a1); a1 = stream.read(); } Image myImage = Toolkit.getDefaultToolkit().createImage(output.toByteArray()); output.close(); } } i have creted the database image_db containig table image_details and inserted a few pictures into the image_path feild of the table which is of medium blob type...now i want to retrieve and display the image stored.when i run the above code i got the error :- Jan 12, 2012 12:55:48 AM cbir.imageAddition.add_image_window jButton5ActionPerformed SEVERE: null java.sql.SQLException: Before start of result set at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927) at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:841) at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5650) at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5570) at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5610) at cbir.imageAddition.ImageRetrieve.(ImageRetrieve.java:49) at cbir.imageAddition.add_image_window.jButton5ActionPerformed(add_image_window.java:280) at cbir.imageAddition.add_image_window.access$400(add_image_window.java:26) at cbir.imageAddition.add_image_window$5.actionPerformed(add_image_window.java:89) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6504) at javax.swing.JComponent.processMouseEvent(JComponent.java:3321) at java.awt.Component.processEvent(Component.java:6269) at java.awt.Container.processEvent(Container.java:2229) at java.awt.Component.dispatchEventImpl(Component.java:4860) at java.awt.Container.dispatchEventImpl(Container.java:2287) at java.awt.Component.dispatchEvent(Component.java:4686) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422) at java.awt.Container.dispatchEventImpl(Container.java:2273) at java.awt.Window.dispatchEventImpl(Window.java:2713) at java.awt.Component.dispatchEvent(Component.java:4686) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707) at java.awt.EventQueue.access$000(EventQueue.java:101) at java.awt.EventQueue$3.run(EventQueue.java:666) at java.awt.EventQueue$3.run(EventQueue.java:664) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87) at java.awt.EventQueue$4.run(EventQueue.java:680) at java.awt.EventQueue$4.run(EventQueue.java:678) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:677) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) at java.awt.EventDispatchThread.run(EventDispatchThread.java:90) can anyone help me please.....:)
more ▼

asked Jan 11 '12 at 03:07 PM

nidheesh gravatar image

nidheesh
1 3 3 3

(comments are locked)
10|600 characters needed characters left

1 answer: sort voted first

Did you add the appropriate mysql connector jar to your path?

more ▼

answered Jun 12 '12 at 07:09 AM

twonjee2002 gravatar image

twonjee2002
1

(comments are locked)
10|600 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1

asked: Jan 11 '12 at 03:07 PM

Seen: 746 times

Last Updated: Jun 12 '12 at 07:09 AM