Results 1 to 8 of 8
  1. #1
    rijuthakona is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default file uploadin in java

    i need code for image uploading into oracle 10g express edition database
    actuallt i have tried the code it works properly when i try to retrieve it in the database, it shows expectd number got blob

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default

    Show us your code that's causing the problem then.
    In code tags.
    As well as the full exception (with stack trace).

  3. #3
    rijuthakona is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default

    import java.io.*;
    import java.net.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;

    /**

    public class ImageUpload extends HttpServlet {


    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    FileInputStream fis = null;
    PreparedStatement ps = null;
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn=DriverManager.getConnection("jdbc:odbc:sample ","system","root");
    String INSERT_PICTURE = "insert into MyPictures(id, name, photo) values (?, ?, ?)";

    conn.setAutoCommit(false);
    File file = new File("C:/Users/Rijju/Pictures/Pictures/sdfgsdfg.jpg");
    fis = new FileInputStream(file);
    ps = conn.prepareStatement(INSERT_PICTURE);
    ps.setString(1, "001");
    ps.setString(2, "name");
    ps.setBinaryStream(3, fis, (int) file.length());
    ps.executeUpdate();
    conn.commit();
    } catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    }

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default

    Code tags?
    Full stack trace?
    Where you are getting your error?

    Come on...if you want help then you have to provide us the information.

  5. #5
    rijuthakona is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default

    package sample;

    import java.io.*;
    import java.net.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;


    public class ImageUpload extends HttpServlet {

    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    FileInputStream fis = null;
    PreparedStatement ps = null;
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn=DriverManager.getConnection("jdbc:odbc:sample ","system","root");
    String INSERT_PICTURE = "insert into MyPictures(id, name, photo) values (?, ?, ?)";

    conn.setAutoCommit(false);
    File file = new File("C:/Users/Rijju/Pictures/Pictures/sdfgsdfg.jpg");
    fis = new FileInputStream(file);
    ps = conn.prepareStatement(INSERT_PICTURE);
    ps.setString(1, "001");
    ps.setString(2, "name");
    ps.setBinaryStream(3, fis, (int) file.length());
    ps.executeUpdate();
    conn.commit();
    } catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    }

    /** Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    }

    /** Returns a short description of the servlet.
    */
    public String getServletInfo() {
    return "Short description";
    }
    // </editor-fold>
    }



    well i am using this code in netbeans 5.5 this code doesnt show any error
    when i try to retireve the image in the database with qurey "select * from MyPictures;" i will get error ORA-00932: inconsistent datatypes: expected NUMBER got BLOB

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default

    Use code tags!
    Java Code:
    Put code in here
    As for the error, that says it's expecting a NUMBER and you gave it a BLOB. Which means your picture column is a NUMBER...not a BLOB.

  7. #7
    rijuthakona is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default

    i have declared the datatype as blob only what code tags we have to use???

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default

    If you quote my post above you'll see them.

    I just noticed that it's on the select you;re having the problem...so why are you showing me the insert?
    If the insert wasn't working you'd be getting errors on that.
    So...how are you doing the select?

Similar Threads

  1. java file reader, jgrasp can't find the file
    By aramiky818 in forum New To Java
    Replies: 3
    Last Post: 04-22-2011, 02:06 AM
  2. how to split large xml file into small xml file in java
    By enggvijaysingh@gmail.com in forum XML
    Replies: 2
    Last Post: 02-07-2011, 09:34 AM
  3. To open an image file such as Jpeg file using JAva Program
    By itmani2020 in forum Advanced Java
    Replies: 10
    Last Post: 07-11-2008, 09:57 AM
  4. Replies: 7
    Last Post: 05-23-2008, 03:46 AM
  5. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •