Results 1 to 3 of 3
  1. #1
    raihan26 is offline Member
    Join Date
    Mar 2010
    Posts
    18
    Rep Power
    0

    Default Inserting Multiple Images into oracle database using JDBC

    how we can insert multiple images into oracle database....

    I wanted to insert multiple images into database using JDBC by reading it from the file... and i am passing photos.txt(my text file) as an input parameter... this is my content of photos.txt file and i have copied all the images into the folder
    " C:\\photos "

    1,in1.jpg,108,19,in-n-out
    2,in2.jpg,187,21,in-n-out
    3,in3.jpg,308,41,in-n-out
    4,in4.jpg,477,52,in-n-out
    5,in5.jpg,530,50,in-n-out


    and i want to store in1.jpg,in2.jpg,in3.jpg,in4.jpg,in5.jpg into the oracle databse using JDBC.... i have tried a lot using BLOB column.... and i have created my table as

    CREATE TABLE PHOTO(
    ID NUMBER NOT NULL PRIMARY KEY ,
    Name BLOB,
    X DOUBLE PRECISION,
    Y DOUBLE PRECISION,
    Tags VARCHAR2(40)
    );


    Java Code:
     try {
          
               
    			// for restaurant
    			System.out.println();System.out.println();System.out.println();
    			System.out.print("  Creating Statement for Photo...\n");
    			
                stmt2 = con.createStatement ();
                          stmt2.executeUpdate("delete from PHOTO");
    			stmt2.executeUpdate("commit");
    			
    			
    			PreparedStatement stmt3 = con.prepareStatement ("INSERT INTO PHOTO VALUES (?, ?, ?, ?, ?)");
    			
                System.out.print("  Create FileReader Object for file: " + inputFileName1 + "...\n");
                FileReader inputFileReader2 = new FileReader(inputFileName1);
                System.out.print("  Create BufferedReader Object for FileReader Object...\n");
                BufferedReader inputStream2   = new BufferedReader(inputFileReader2);
                String inLine2 = null;
                
                String[] tokens;
     //             String[] imageFilenames = {"c:\\photos\\in1.jpg","c:\\photos\\in2.jpg","c:\\photos\\in3.jpg","c:\\photos\\in4.jpg","c:\\photos\\in5.jpg",
     //  "c:\\photos\\in6.jpg","c:\\photos\\in7.jpg","c:\\photos\\in8.jpg","c:\\photos\\in9.jpg","c:\\photos\\in10.jpg","c:\\photos\\arb1.jpg","c:\\photos\\arb2.jpg",
     //  "c:\\photos\\arb3.jpg","c:\\photos\\arb4.jpg","c:\\photos\\arb5.jpg","c:\\photos\\den1.jpg","c:\\photos\\den2.jpg","c:\\photos\\den3.jpg",
     //  "c:\\photos\\den4.jpg","c:\\photos\\den5.jpg","c:\\photos\\hop1.jpg","c:\\photos\\hop2.jpg","c:\\photos\\hop3.jpg","c:\\photos\\hop4.jpg","c:\\photos\\hop5.jpg"};
        
              File file = new File("C:\\photos\\in1.jpg");            \\ ( Just for example  )
              FileInputStream fs = new FileInputStream(file);
     
                
                while ((inLine2 = inputStream2.readLine()) != null) {
                   tokens= inLine2.split(",");
                st2 = new StringTokenizer(inLine2, DELIM);
                    
               
                    
                      stmt3.setString(1, tokens[0]);
                   stmt3.setBinaryStream(2, fs, (int)(file.length()));
                   stmt3.setString(3, tokens[2]);
                   stmt3.setString(4, tokens[3]);
                   stmt3.setString(5, tokens[4]);
                   stmt3.execute(); //execute the prepared statement
                   stmt3.clearParameters();

    As i am able to read one image by my above code in1.jpg in to the oracle database.... Any suggestions how can i insert multiple images into oracle database by looking at my code or any other changes....
    Can you give me the example on the basis of the above code of mine...

  2. #2
    jambon is offline Member
    Join Date
    Nov 2009
    Posts
    9
    Rep Power
    0

    Default Re: Inserting Multiple Images...

    Hi!
    How about this?
    Java Code:
                
                while ((inLine2 = inputStream2.readLine()) != null) {
                   tokens= inLine2.split(",");
                    String fname = tokens[1];
                    String path = "C:\\photos\\"+fname;
                    File file = new File(path);           
                    FileInputStream fs = new FileInputStream(file);
    
                st2 = new StringTokenizer(inLine2, DELIM);
                    
               
                    
                      stmt3.setString(1, tokens[0]);
                   stmt3.setBinaryStream(2, fs, (int)(file.length()));
                   stmt3.setString(3, tokens[2]);
                   stmt3.setString(4, tokens[3]);
                   stmt3.setString(5, tokens[4]);
                   stmt3.execute(); //execute the prepared statement
                   stmt3.clearParameters();
    -Jambon

  3. #3
    raihan26 is offline Member
    Join Date
    Mar 2010
    Posts
    18
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 02-02-2010, 01:33 PM
  2. Replies: 1
    Last Post: 04-23-2009, 07:55 PM
  3. Inserting multiple shapes using mouseListener
    By thayalan in forum Java 2D
    Replies: 1
    Last Post: 03-14-2009, 02:43 PM
  4. Using JDBC to connect to ORACLE database
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-10-2008, 11:27 AM
  5. Inserting file in to database
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-07-2008, 08:39 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
  •