억 대 데이터 양 - JDBC 데이터베이스 삽입
package com.database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
* , JDBC , .
* 、 , 100 jdbc .
* 、 , 5 .
* @author Administrator
*/
public class Import {
private static final String JDBC_URL = "jdbc:oracle:thin:@localhost:1521:orcl";
private static final String JDBC_USER = "ttt";
private static final String JDBC_PASSWORD = "pw123456";
private static final String JDBC_SQL = "insert into tb_test (col1,col2) values (?,?)";
public static void main(String[] args) throws Exception {
Class.forName("oracle.jdbc.driver.OracleDriver");
exe(100000005);//1
}
public static void exe(int sl) throws SQLException{
int SIZE = 1000000;// ( 100 )
int page = sl/SIZE;//
for (int i = 0; i < page; i++) {//
execute(i*SIZE,(i+1)*SIZE);
}
if(sl%SIZE != 0){
execute(page*SIZE,sl);
}
}
private static void execute(int begin, int end) throws SQLException {
Connection conn = null;
PreparedStatement pst= null;
try {
conn = DriverManager.getConnection(JDBC_URL, JDBC_USER,JDBC_PASSWORD);
System.out.println(" :" + begin + " - " + end);
conn.setAutoCommit(false);//
pst = conn.prepareStatement(JDBC_SQL);
int recordNum = 0; //
int commit_size = 50000;// 5
for (int i = begin; i < end; i++) {
recordNum++; //
pst.setString(1, "n" + i);
pst.setString(2, "v" + i);
pst.addBatch();
if (recordNum % commit_size == 0) {
pst.executeBatch();
conn.commit();
System.out.println(" :" + i);
conn.setAutoCommit(false);
pst = conn.prepareStatement(JDBC_SQL);
}
}
if (recordNum % commit_size != 0) {
pst.executeBatch();
conn.commit();
System.out.println(" :" + recordNum);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (pst != null) pst.close();
} catch (SQLException e) {
e.printStackTrace();
}finally{
try{
if (conn != null) conn.close();
System.out.println(" !");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
깊이 중첩된 객체를 정확히 일치 검색 - PostgreSQL목차 * 🚀 * 🎯 * 🏁 * 🙏 JSON 객체 예시 따라서 우리의 현재 목표는 "고용주"사용자가 입력한 검색어(이 경우에는 '요리')를 얻고 이 용어와 정확히 일치하는 모든 사용자 프로필을 찾는 것입니다. 즐거운 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.