|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
image retrieval from databasehi,
i hav stored image into database using servlet............... but when iam retrieving iam fcaing error ...... java .lang.unsupportedoperation on executing getblob() method............... my code as follows: import java.sql.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class DisplayBlobExample extends HttpServlet{ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { Blob image = null; Connection con = null; PreparedStatement stmt = null; ResultSet rs = null; ServletOutputStream out = response.getOutputStream(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:sud","scott","tiger"); stmt = con.prepareStatement("select * from pic1");;out.println("erer"); rs = stmt.executeQuery();out.println("erer2"); if (rs.next()) { out.println("erer4"); image = rs.getBlob(1);out.println("erer3"); } else { response.setContentType("text/html"); out.println("<html><head><title>Display Blob Example</title></head>"); out.println("<body><h4><font color=\'red\'>image not found for given id</font></h4></body></html>"); return; } response.setContentType("image/jpg"); InputStream in = image.getBinaryStream(); int length = (int) image.length(); int bufferSize = 20242; byte[] buffer = new byte[bufferSize]; while ((length = in.read(buffer)) != -1) { out.write(buffer, 0, length); } in.close(); out.flush(); } catch (Exception e) { response.setContentType("text/html"); out.println("<html><head><title>Unable To Display image</title></head>"); out.println("<body><h4><font color=\'red\'>Image Display Error=" + e + "</font></h4></body></html>"); return; } finally { try { rs.close(); stmt.close(); con.close(); } catch (SQLException e) { e.printStackTrace(); } } } } plz help to get rid of this............................. suggest me the code to retrieve image from sql db and display it in browser |
|
|
Re: image retrieval from databasehi sudhir,
As a primary check, check if the first column of the result from "select * from pic1" contains the image and not any primary key or something else. Regards, Kartik Nayak On Fri, Jul 10, 2009 at 1:31 PM, sudhir ms <sudhir_251838@...>wrote: > hi, > > i hav stored image into database using servlet............... but when iam > retrieving iam fcaing error ...... java .lang.unsupportedoperation on > executing getblob() method............... > > > my code as follows: > > > import java.sql.*; > import java.io.*; > import javax.servlet.*; > import javax.servlet.http.*; > public class DisplayBlobExample extends HttpServlet{ > public void doGet(HttpServletRequest request, HttpServletResponse > response) > throws IOException,ServletException { > Blob image = null; > Connection con = null; > PreparedStatement stmt = null; > ResultSet rs = null; > ServletOutputStream out = response.getOutputStream(); > try { > Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); > con = DriverManager.getConnection("jdbc:odbc:sud","scott","tiger"); > stmt = con.prepareStatement("select * from > pic1");;out.println("erer"); > rs = stmt.executeQuery();out.println("erer2"); > if (rs.next()) { > out.println("erer4"); image = rs.getBlob(1);out.println("erer3"); > } else { > response.setContentType("text/html"); > out.println("<html><head><title>Display Blob > Example</title></head>"); > out.println("<body><h4><font color=\'red\'>image not found for > given id</font></h4></body></html>"); > return; > } > response.setContentType("image/jpg"); > InputStream in = image.getBinaryStream(); > int length = (int) image.length(); > int bufferSize = 20242; > byte[] buffer = new byte[bufferSize]; > while ((length = in.read(buffer)) != -1) { > out.write(buffer, 0, length); > } > in.close(); > out.flush(); > } catch (Exception e) { > response.setContentType("text/html"); > out.println("<html><head><title>Unable To Display > image</title></head>"); > out.println("<body><h4><font color=\'red\'>Image Display Error=" + e > + "</font></h4></body></html>"); > return; > } finally { > try { > rs.close(); > stmt.close(); > con.close(); > } catch (SQLException e) { > e.printStackTrace(); > } > } > } > } > > > plz help to get rid of this............................. suggest me the > code to retrieve image from sql db and display it in browser > > > ------------------------------------ > > http://twincling.org/ > http://twitter.com/twincling > ---------------------------------------- > Yahoo! Groups Links > > > > [Non-text portions of this message have been removed] |
|
|
Re: image retrieval from databasecreate table pic1(image blob);
this is my table.... and i hav checked it image was storing correctly...... help me to get out of it --- On Fri, 10/7/09, Kartik Nayak <kartik1507@...> wrote: From: Kartik Nayak <kartik1507@...> Subject: Re: [twincling] image retrieval from database To: twincling@... Date: Friday, 10 July, 2009, 1:52 PM hi sudhir, As a primary check, check if the first column of the result from "select * from pic1" contains the image and not any primary key or something else. Regards, Kartik Nayak On Fri, Jul 10, 2009 at 1:31 PM, sudhir ms <sudhir_251838@ yahoo.co. in>wrote: > hi, > > i hav stored image into database using servlet..... ......... . but when iam > retrieving iam fcaing error ...... java .lang.unsupportedop eration on > executing getblob() method...... ......... > > > my code as follows: > > > import java.sql.*; > import java.io.*; > import javax.servlet. *; > import javax.servlet. http.*; > public class DisplayBlobExample extends HttpServlet{ > public void doGet(HttpServletRe quest request, HttpServletResponse > response) > throws IOException, ServletException { > Blob image = null; > Connection con = null; > PreparedStatement stmt = null; > ResultSet rs = null; > ServletOutputStream out = response.getOutputS tream(); > try { > Class.forName( "sun.jdbc. odbc.JdbcOdbcDri ver"); > con = DriverManager. getConnection( "jdbc:odbc: sud","scott" ,"tiger") ; > stmt = con.prepareStatemen t("select * from > pic1");;out. println(" erer"); > rs = stmt.executeQuery( );out.println( "erer2"); > if (rs.next()) { > out.println( "erer4"); image = rs.getBlob(1) ;out.println( "erer3"); > } else { > response.setContent Type("text/ html"); > out.println( "<html><head> <title>Display Blob > Example</title> </head>") ; > out.println( "<body><h4> <font color=\'red\ '>image not found for > given id</font></h4> </body></ html>"); > return; > } > response.setContent Type("image/ jpg"); > InputStream in = image.getBinaryStre am(); > int length = (int) image.length( ); > int bufferSize = 20242; > byte[] buffer = new byte[bufferSize] ; > while ((length = in.read(buffer) ) != -1) { > out.write(buffer, 0, length); > } > in.close(); > out.flush(); > } catch (Exception e) { > response.setContent Type("text/ html"); > out.println( "<html><head> <title>Unable To Display > image</title> </head>") ; > out.println( "<body><h4> <font color=\'red\ '>Image Display Error=" + e > + "</font></h4> </body></ html>"); > return; > } finally { > try { > rs.close(); > stmt.close() ; > con.close(); > } catch (SQLException e) { > e.printStackTrace( ); > } > } > } > } > > > plz help to get rid of this........ ......... ......... ... suggest me the > code to retrieve image from sql db and display it in browser > > > ------------ --------- --------- ------ > > http://twincling. org/ > http://twitter. com/twincling > ------------ --------- --------- --------- - > Yahoo! Groups Links > > > > [Non-text portions of this message have been removed] Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com [Non-text portions of this message have been removed] |
|
|
Re: image retrieval from database2009/7/10 sudhir ms <sudhir_251838@...>
> hi, > > i hav stored image into database using servlet............... but when iam > retrieving iam fcaing error ...... java .lang.unsupportedoperation on > executing getblob() method............... > > > my code as follows: > > > import java.sql.*; > import java.io.*; > import javax.servlet.*; > import javax.servlet.http.*; > public class DisplayBlobExample extends HttpServlet{ > public void doGet(HttpServletRequest request, HttpServletResponse > response) > throws IOException,ServletException { > Blob image = null; > Connection con = null; > PreparedStatement stmt = null; > ResultSet rs = null; > ServletOutputStream out = response.getOutputStream(); > try { > Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); > con = DriverManager.getConnection("jdbc:odbc:sud","scott","tiger"); > stmt = con.prepareStatement("select * from > pic1");;out.println("erer"); > rs = stmt.executeQuery();out.println("erer2"); > if (rs.next()) { > out.println("erer4"); image = rs.getBlob(1);out.println("erer3"); > } else { > response.setContentType("text/html"); > out.println("<html><head><title>Display Blob > Example</title></head>"); > out.println("<body><h4><font color=\'red\'>image not found for > given id</font></h4></body></html>"); > return; > } > response.setContentType("image/jpg"); > InputStream in = image.getBinaryStream(); > int length = (int) image.length(); > int bufferSize = 20242; > byte[] buffer = new byte[bufferSize]; > while ((length = in.read(buffer)) != -1) { > out.write(buffer, 0, length); > } > in.close(); > out.flush(); > } catch (Exception e) { > response.setContentType("text/html"); > out.println("<html><head><title>Unable To Display > image</title></head>"); > out.println("<body><h4><font color=\'red\'>Image Display Error=" + e > + "</font></h4></body></html>"); > return; > } finally { > try { > rs.close(); > stmt.close(); > con.close(); > } catch (SQLException e) { > e.printStackTrace(); > } > } > } > } > > plz help to get rid of this............................. suggest me the > code to retrieve image from sql db and display it in browser > > are you using Tomcat & MS Access DB? I did using these two as part of my academics... We put our .java file into the web-inf/classes folder of Tomcat & compiled the .java file there (Please note: no java command only javac)... Then after compiling, linked the servlet into the web.xml file & called from browser ( by url-pattern which you define in web.xml file). Else you can make another folder out of the tomcat directory & make a web.xml & index.html files. Also put your .class file into the new folder then make a .war file jar cvf somename.war *.* index.html Give this command when on top of the folder that you make. else the *.* will include all the unnecessary sub-folders & files... The web.xml ( if u make outside tomcat) will look something like: <?xml version = "1.0" encoding = "utf-8"?> <web-app> <servlet> <servlet-name>DisplayBlobExample</servlet-name> <servlet-class>DisplayBlobExample</servlet-class> </servlet> <servlet-mapping> <servlet-name>DisplayBlobExample</servlet-name> <url-pattern>/DisplayBlobExample</url-pattern> </servlet-mapping> </web-app> Deploy the .war file on Tomcat...I guess it shud work now... -- thanks for your time, Pratik K Anand http://twitter.com/pratik_k_anand [Non-text portions of this message have been removed] |
| Free embeddable forum powered by Nabble | Forum Help |