Repository navigation
Expand file tree
/
Copy pathDataLoader.java
More file actions
69 lines (55 loc) · 2.06 KB
/
Copy pathDataLoader.java
File metadata and controls
69 lines (55 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
/**
* Created by manojperiathambi on 2/9/16.
*/
public class DataLoader {
public static void main(String... arg) throws SQLException {
new DataLoader().loadData();
}
public void loadData() throws SQLException {
//STEP 4: Execute a query
System.out.println("Creating statement...");
try(Connection conn = OracleConnection.getConnection()) {
conn.setAutoCommit(false);
Scanner scan = new Scanner(System.in);
System.out.println("How many records you want to load ?");
Long totalRecords = scan.nextLong();
System.out.println("What is the page size ?");
int pageSize = scan.nextInt();
while (totalRecords > 0) {
List<InputDataModel> inpList = new ArrayList<>(pageSize);
try(PreparedStatement stmt = conn.prepareStatement("");) {
ResultSet rs = stmt.executeQuery();
int tmpPage = pageSize;
while (tmpPage-- > 0) {
inpList.add(getInputModel(rs));
}
}
try(PreparedStatement insertStmt = conn.prepareStatement("");) {
for (InputDataModel in : inpList) {
prepareData(insertStmt, in).addBatch();
}
int[] count = insertStmt.executeBatch();
}
conn.commit();
totalRecords = totalRecords - pageSize;
}
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("Loaded all the data");
}
private PreparedStatement prepareData(PreparedStatement insertStmt, InputDataModel in) {
return null;
}
private InputDataModel getInputModel(ResultSet rs) {
return null;
}
}