0 Replies Latest reply: Dec 9, 2011 9:32 AM by 866724 RSS

    Exception - getBLOB not implemented

    866724
      import java.io.IOException;
      import java.io.InputStream;
      import java.sql.Blob;
      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import java.sql.Statement;
      
      import javax.servlet.ServletException;
      import javax.servlet.ServletOutputStream;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      
      public class DisplayBlobServlet extends HttpServlet {
      
          @Override
          public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,
                  ServletException {
      //        String photoid = request.getParameter("txtid");
              Blob photo = null;
              Connection conn = null;
              Statement stmt = null;
              ResultSet rs = null;
              String query = "select plikimage from testimage where id=2";
              ServletOutputStream out = response.getOutputStream();
      
              try {
                  conn = getOracleConnection();
              } catch (Exception e) {
                  response.setContentType("text/html");
                  out.println("<html><head><title>Person Photo</title></head>");
                  out.println("<body><h1>Database Connection Problem.</h1></body></html>");
                  return;
              }
      
              try {
                  stmt = conn.createStatement();
                  rs = stmt.executeQuery(query);
                  if (rs.next()) {
                      photo = rs.getBlob(1);
      
                  } else {
                      response.setContentType("text/html");
                      out.println("<html><head><title>Person Photo</title></head>");
                      out.println("<body><h1>No photo found for id= 001 </h1></body></html>");
                      return;
                  }
      
                  response.setContentType("image/jpg");
                  InputStream in = photo.getBinaryStream();
                  int length = (int) photo.length();
      
                  int bufferSize = 1024;
                  byte[] buffer = new byte[bufferSize];
      
                  while ((length = in.read(buffer)) != -1) {
                      System.out.println("writing " + length + " bytes");
                      out.write(buffer, 0, length);
                  }
      
                  in.close();
                  out.flush();
              } catch (SQLException e) {
                  response.setContentType("text/html");
                  out.println("<html><head><title>Error: Person Photo</title></head>");
                  out.println("<body><h1>Error=" + e.getMessage() + "</h1></body></html>");
                  return;
              } finally {
                  try {
                      rs.close();
                      stmt.close();
                      conn.close();
                  } catch (SQLException e) {
                      e.printStackTrace();
                  }
              }
          }
      
          public static Connection getOracleConnection() throws Exception {
              String driver = "oracle.jdbc.driver.OracleDriver";
              String url = "jdbc:oracle:thin:@localhost:1521:ORCL";
              String username = "SYSTEM";
              String password = "qazwsx1";
      
              Class.forName(driver); // load Oracle driver
              Connection conn = DriverManager.getConnection(url, username, password);
              return conn;
          }
      }
      This servlet unfortunately gives me sucha a exception :
      getBLOB not implemented for class oracle.jdbc.driver.T4CNamedTypeAccessor
      What to do ? Much appreciated for any help.

      Edited by: user10484812 on 2011-12-09 07:32

      Edited by: user10484812 on 2011-12-09 07:32