3 Replies Latest reply: Dec 28, 2012 1:24 PM by Edward D.G. RSS

    Upload a entire Directory's File to Oracle DB.

    Edward D.G.
      I put jpg files into a Directory for be upload to Oracle database.
      I need to do a program that get all file's names in this Directory and upload to a Oracle DB.
      How can i get all file's name from Dictory?????

      My Jdev version 11.1.2.3.

      Edited by: Edward D.G. on Dec 27, 2012 1:49 PM
        • 1. Re: Upload a entire Directory's File to Oracle DB.
          Shay Shmeltzer-Oracle
          It's not exactly clear which technologies you are using or what specifically you want to upload, the image or the file name...
          Here are some google results:
          http://www.javaprogrammingforums.com/java-programming-tutorials/3-java-program-can-list-all-files-given-directory.html

          http://www.srikanthtechnologies.com/blog/java/fileupload.aspx
          • 2. Re: Upload a entire Directory's File to Oracle DB.
            452071
            Do you want this to happen as a batch operation? or do want to be able to display all the pictures to an ADF UI and then send them to the DB. Here are some resources for working with Blobs on ADF applicaitons:
            www.connotea.org/user/jdeveloper/tag/blob

            Juan Camilo
            • 3. Re: Upload a entire Directory's File to Oracle DB.
              Edward D.G.
              This is what i wanted to do in a Java Desktop Application (ADF). thanks for help me. B-)

              private void Upload(ActionEvent e) {       
              File[] file = new File("C:\\jpg\\").listFiles();
              Connection cnn = null;

              try {    
              Class.forName("oracle.jdbc.driver.OracleDriver");
              cnn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.10.1:1521:DemoStore", "salesuser", "salespassword");
              cnn.setAutoCommit(false);
              } catch (SQLException f) {
              System.out.println(f);
              } catch (ClassNotFoundException f) {
              System.out.println(f);
              }

              for (int i = 0; i < file.length; i++) {
              try {
              cnn.setAutoCommit(false);
              PreparedStatement ps = cnn.prepareStatement(" BEGIN inser_file(?,?,?); END;");
              ps.setString(1, file.getName());
              ps.setString(2, "jpg");
              ps.setBinaryStream(3, new FileInputStream(file[i]), (int)file[i].length());
              ps.executeUpdate();
              cnn.commit();
              ps.close();
              cnn.close();
              } catch (SQLException f) {
              System.out.println(f);
              } catch (FileNotFoundException f) {
              System.out.println(f);
              }
              }
              }