1 Reply Latest reply: Apr 2, 2014 6:21 AM by Jani Rautiainen-Oracle RSS

    Storing image in java database cloud

    43bdb272-cf53-4f63-bb03-02cee2df5adb

      I want to store images that are present in my machine to the cloud, for that i wrote following servlet but it keeps giving me null pointer exception , Images are stored in the same folder as my Serclet in my project

       

      Context ctx = null;

              Hashtable ht = new Hashtable();

              ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");

       

              Connection conn = null;

              Statement stmt = null;

              ResultSet rs = null;

              // out.print("system");

       

              try {

                  ctx = new InitialContext(ht);

                  javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("javatrial5196db");

                  PreparedStatement ps = conn.prepareStatement("insert into table3 values(?,?)");

       

                  File imgFile = new File(getClass().getResource("Vehicle.png").toURI());

                  out.println(imgFile.getName());

                  ps.setString(1, imgFile.getName());

                  ps.setBinaryStream(2, new FileInputStream(imgFile), new FileInputStream(imgFile).available());

                  ps.executeUpdate();

        

       

                  conn.close();

                  stmt.close();

      }