Results 1 to 3 of 3
- 03-27-2010, 08:21 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 16
- Rep Power
- 0
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...
- 03-28-2010, 05:26 PM #2
Member
- Join Date
- Nov 2009
- Posts
- 8
- Rep Power
- 0
Re: Inserting Multiple Images...
Hi!
How about this?
-JambonJava 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();
- 04-01-2010, 04:35 AM #3
Member
- Join Date
- Mar 2010
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
JDBC problem with multiple resultsets on mysql database: getUpdateCount() always zero
By plica10 in forum JDBCReplies: 3Last Post: 02-02-2010, 01:33 PM -
inserting multiple rows from one table into another
By xcallmejudasx in forum JDBCReplies: 1Last Post: 04-23-2009, 07:55 PM -
Inserting multiple shapes using mouseListener
By thayalan in forum Java 2DReplies: 1Last Post: 03-14-2009, 02:43 PM -
Using JDBC to connect to ORACLE database
By Java Tip in forum Java TipReplies: 0Last Post: 02-10-2008, 11:27 AM -
Inserting file in to database
By Java Tip in forum Java TipReplies: 0Last Post: 01-07-2008, 08:39 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks