We help IT Professionals succeed at work.

bulk upload data into mysql through jsp interface.

pradapkumar
pradapkumar asked
on
644 Views
Last Modified: 2012-05-08
I like to upload data (around 20000 records) into remote mysql database server through jsp interface. How to go about it? I am new to jsp environment. But I have little knowledge about php web programming. I have already established a connection to remote mysql server.
Comment
Watch Question

Murali MurugesanFull stack Java developer
CERTIFIED EXPERT

Commented:
My suggestion would be to create a oracle stored procedure that queries the records and inserts to the remote database in a batch say 5k records at a time and do a commit after every 5k records insert.

Alternatively in Java,

 Write the JDBC code to insert into your MySql DB and then call that method from JSP.

-Murali*
From where it is suppose to pick up these 20K records? If it is from user input or something, then may be you will have to have a upload file first to your jsp and then a JDBC connection on which you can pass these records.
CERTIFIED EXPERT

Commented:
write stored procedure !!

Author

Commented:
The code I have made is working in testing environment which is attatched here. But in remote server, in the following line,

----> FileInputStream fstream = new FileInputStream("update1.txt");

 I can't get the file path. Any suggestions please.
<%  
    
int i=0;
try{
   FileInputStream fstream = new FileInputStream("update1.txt");
   DataInputStream in = new DataInputStream(fstream);
   BufferedReader br = new BufferedReader(new InputStreamReader(in));
   String strLine;
   
   DBConnection dbConn = new DBConnection();
   Connection conn = dbConn.getConnection();
   Statement stmt=null;
 
   while ((strLine = br.readLine()) != null)   {
     stmt = conn.createStatement();
     stmt.executeUpdate(strLine);
     i++;
   }
   in.close();
   
   }catch (Exception e){ 
      System.err.println("Error: " + e.getMessage());
   }
   out.println("Total " + i + " records has been added");
 
%>

Open in new window

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.