tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Reilly" <step...@streamon.net>
Subject RE: how to read a text file and store into mysql databse --JAVA
Date Wed, 11 Aug 2004 09:56:17 GMT
Maruthi,

Check out the javadoc (http://java.sun.com/j2se/1.4.2/docs/api/) for
PreparedStatement:
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/PreparedStatement.html


In your case (and I have never used these before, but this should do):

PreparedStatement prestate = websiteDbCon.prepareStatement("INSERT INTO
submitjobs (CPU, Architecture, execute) VALUES (?, ?, ?)"); 

//make sure the statement is clear
prestate.clearParameters();

//the input for the CPU field
Prestate.setString(1, strInputCpu);

//the input for the architecture field
Prestate.setString(2, strInputArch);

/*Set up the path to the file
(http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html)*/
String strFileName = strPath + "ravu.txt";
File file = new File(strFileName);

// add the file to the statement
prestate.setBinaryStream(3, //parameter reference
new FileInputStream(file), //file to insert
(int) file.length()); //length of file

//excute the statement
prestate.execute();


Credit where credit's due: this is a vicious thieving of Mike's answer,
Stephen


-----Original Message-----
From: Maruthi [mailto:maruthibabu_2k@yahoo.com] 
Sent: 11 August 2004 10:18
To: tomcat-user@jakarta.apache.org; tomcat-user@mlfowler.com
Subject: Re: how to read a text file and store into mysql databse --JAVA

 
Hello Many thanks for your reply.My database table structure is like
this.I have 3 fields in the table and field i want to insert file is
'execute'
 
Table Name ::submitjobs

Field               Type      
CPU               varchar(25) 
Architecture    varchar(25) 
execute           blob       
 
The file name i want to insert into the filed 'execute' is 'ravu.txt'.I
didn't understood this statement properly.Can you explain this with
respect to my above table structure.
 
PreparedStatement prestate = websiteDBCon.prepareStatement("" +
"INSERT INTO Collateral (AccountTypeID," +
"Document" +
"VALUES (?)");
 
 
Thank you very much for your time and patience,
Pl reply.
Maruthi.
 

Mike Fowler <tomcat-user@mlfowler.com> wrote:
Hi Maruthi,

This should do what your after. The variable file is obviously the
file you want to insert into the database.

PreparedStatement prestate = websiteDBCon.prepareStatement("" +
"INSERT INTO Collateral (AccountTypeID," +
"Document" +
"VALUES (?)");

//make sure the statement is clear
prestate.clearParameters();

//add the file to the statement
prestate.setBinaryStream(1, //parameter reference
new FileInputStream(file), //file to insert
(int) file.length()); //length of file

//excute the statement
prestate.execute();

Hope this helps!

-Mike Fowler
"I could be a genius if I just put my mind to it, and I,
I could do anything, if only I could get 'round to it"


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


		
---------------------------------
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message