Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes Issue with entering data from Java class file to Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Issue with entering data from Java class file to Database" Watch "Issue with entering data from Java class file to Database" New topic
Author

Issue with entering data from Java class file to Database

rajarshi roy
Greenhorn

Joined: Feb 14, 2010
Posts: 21
I am using a Java class file to read data from an Excel sheet using the Apache POI API,and then using Preparedstatement to finally enter the data into database.Now I am using an insert statement in a for-loop that enters one set of data at one time.
Somewhat like this....


This process seems to take a lot of time.Data is read from the Excel sheet instantly.But it takes time to insert in to the table.Is there any way,that I store all the data in an Array/ArrayList and then finally enter them altogether,at once,instead of entering one set of data at one time? I think if it can be done,then the entire process will become much faster.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

Yes. There is an executeBatchUpdate() method you can use to have less trips to the database. Depending on the size of the file, you may want to read parts of the file at a time (in a loop) so you don't have the whole file in memory.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
rajarshi roy
Greenhorn

Joined: Feb 14, 2010
Posts: 21
I am not getting it.My problem is I am using an insert statement in a for-loop to enter data.I want to do the transaction at once.Let us say that I concatenate the data in a comma-separated String,or put the data in to an array and then insert it altogether.

I was trying to use ArrayDescriptor. But I am facing this weird exception


Exception encountered 1java.sql.SQLException: invalid name pattern: apps.hr_type_nom_temp
Exception encountered 3java.sql.SQLException: invalid name pattern: apps.hr_type_nom_temp



The code is, as follows



Any idea,where exactly I am making the mistake?
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1131

Roy,
Interface Statement declares method addBatch.
I suggest you search the Internet for "addBatch example".

And by the way, Jeanne, I could not find any method named executeBatchUpdate in the javadocs.

Good Luck,
Avi.

Krish Khan
Ranch Hand

Joined: Dec 14, 2009
Posts: 46
Hi,



I am trying to read an excel which has Thai language init I could able to read the file but the thai characters are appearing as ??? ??? instead of "นายสุรชัย พิมพ์รำลึก".


my code is :



You can use this code to read ordinary(English characters) Excel (.xls). Please try this code it may help you .

And also I am looking for someone who can solve my problem of reading thai language characters and saving it in database.
 
 
subject: Issue with entering data from Java class file to Database