Reputation: 265
what is the best way to insert millions of records into table.
Some approaches are:
1) writing jdbc program to insert data.
2) writing pl/sql procedure to insert data.
can any one please suggest other approaches and best as well.
Upvotes: 1
Views: 2553
Reputation: 3436
Batch processing with JDBC API will do the job for such huge no of records.
Upvotes: 0
Reputation: 6152
I assume it is mysql:
INSERT INTO x (a,b)
VALUES
('1', 'one'),
('2', 'two'),
('3', 'three')
If it is one time only issue, I dont think java should be involoved.
I suggest you tell us where do you take your data from?
Upvotes: 1
Reputation: 15483
I would suggest that you should use the Data Migration tool that comes with most of the databases like MS Sql Server.
Otherwise JDBC/PL-SQL will behave same, But Its better to run all the queries in a Transaction and PL-SQL will have a bit better hand on managing Transaction.
But In Java you can read the source a bit efficiently then PL-SQL (if it is possible) like if you have a source of XML, CSV file etc.
Upvotes: 3
Reputation: 89209
You can also do a batch insert in JDBC (if your JDBC driver is 2.0 and higher).
Upvotes: 2
Reputation: 5321
PL/SQL procedure will let you handle transactions effectively. It also depends on where are you going to read the data from? Not that PLSQL can't do some stuff but Java might be better at it.
Upvotes: 0