Forum Stats

  • 3,836,894 Users
  • 2,262,203 Discussions
  • 7,900,136 Comments

Discussions

Upload a entire Directory's File to Oracle DB.

Edward D.G.
Edward D.G. Member Posts: 167
edited Dec 28, 2012 2:24PM in JDeveloper and ADF
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

Best Answer

  • Shay Shmeltzer-Oracle
    Shay Shmeltzer-Oracle Director of Product Management for Oracle's Cloud Development Tools Posts: 16,870 Employee
    Answer ✓
    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

Answers

  • Shay Shmeltzer-Oracle
    Shay Shmeltzer-Oracle Director of Product Management for Oracle's Cloud Development Tools Posts: 16,870 Employee
    Answer ✓
    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
  • 452071
    452071 Member Posts: 443
    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
    452071
  • Edward D.G.
    Edward D.G. Member Posts: 167
    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);
    }
    }
    }
This discussion has been closed.