웹에서 발견한 소스입니다..
유용하게 쓰일수도 있을것 같아 올립니다.
사이트 url;
http://home.clara.net/dwotton/dba/java_insert/test3.txt
소스코드
/*
test3.java
----------
This java class demonstrates inserting 500,000 rows into a table, one row at
a time. With just a single commit at the end of the entire job.
Auto-commit is switched off.
Bind variables are used for the insert statements. This reduces parsing effort.
You will need to change a few constants (database name, schema owner, etc.) before
running this program in your environment. See the code below for details.
compile using:
set CLASSPATH=.;C:oracleora81jdbclibclasses111.zip
javac test3.java
Written: 18/10/01, Dave Wotton
For more information about this test, including results and conclusions,
refer to http://home.clara.net/dwotton/dba/java_insert.htm
*/
import java.io.*;
import java.sql.*;
import java.util.*;
import java.text.*;
public class test3
{
public static void main (String[] args) throws SQLException
{
int recCount = 0;
String record = null;
// You will need to make the following substitutions before running the program:
//
// server_ipname -> the IP name of your Oracle server
// oracle_sid -> the SID of your Oracle instance
// Login -> the owner of the schema holding the dave_test1 table
// Password -> the schema owner's password.
String connect_string = "jdbc:oracle:thin:@server_ipname:1521:oracle_sid";
String Login = "scott";
String Password = "tiger";
// create a Date variable ...
java.util.Date now = new java.util.Date();
// Define a dateformatter to display date variables ...
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.DEFAULT);
// Timestamp the start of the run ...
long startTime = System.currentTimeMillis();
// convert the startTime into Date format
now.setTime(startTime);
// and display the start of run stats
System.out.println("Time now: " + df.format(now) );
// Load Oracle driver ...
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
// Connect to the database ...
Connection conn =
DriverManager.getConnection (connect_string, Login, Password );
// Disable auto-commit ...
conn.setAutoCommit (false);
try {
// define a buffered reader, connected to the file "dave_test.in" ...
FileReader fr = new FileReader("dave_test.in");
BufferedReader br = new BufferedReader(fr);
// define a string to hold the records returned by the buffered reader ...
record = new String();
// Prepare an Oracle statement (with bind variables) to perform the update ...
PreparedStatement pstmt =
conn.prepareStatement ("insert into dave_test1 values(?,?,?,?)" );
// Do the real processing ...
// ----------------------
while ((record = br.readLine()) != null)
{
recCount++;
// define a tokenizer to split the input record into fields, using ':' as
// the delimiter.
StringTokenizer st = new StringTokenizer(record, ":");
String l_key = st.nextToken(); // an integer
String l_col1 = st.nextToken(); // a small word
String l_col2 = st.nextToken(); // a digit in the range 0-6
String l_col3 = st.nextToken(); // a long string
// and insert the row into the database ...
pstmt.setInt(1,Integer.parseInt( l_key.trim() ) );
pstmt.setString(2,l_col1.trim() );
pstmt.setInt(3,Integer.parseInt( l_col2.trim() ) );
pstmt.setString(4,l_col3.trim() );
pstmt.executeUpdate (); // Do the update
// if ( recCount > 100 ) { break; }
}
Statement stmt = conn.createStatement ();
stmt.executeQuery ("commit");
pstmt.close(); // close the prepared statement object used for the inserts
stmt.close(); // close the statement object used for the commit
conn.close(); // close the database connection
// Timestamp the end of the run ...
long stopTime = System.currentTimeMillis();
// Calculate the duration ...
long runTime = stopTime - startTime;
// convert to mm:ss ...
long mins = runTime / 60000;
long secs = ( runTime % 60000 ) / 1000;
String mins_str = mins + "" ;
if ( mins_str.length() == 1 ) { mins_str = '0' + mins_str; }
String secs_str = secs + "";
if ( secs_str.length() == 1 ) { secs_str = '0' + secs_str; }
String Duration = mins_str + ":" + secs_str;
// convert the stopTime into Date format
now.setTime(stopTime);
// and display the end of run stats
System.out.println("Time now: " + df.format(now) + " Run time: " + runTime + "ms (" + Duration + ")" );
} catch (IOException e) {
// catch possible io errors from readLine()
System.out.println("Uh oh, got an IOException error!");
e.printStackTrace();
}
} // end of main
} // end of class
유용하게 쓰일수도 있을것 같아 올립니다.
사이트 url;
http://home.clara.net/dwotton/dba/java_insert/test3.txt
소스코드
/*
test3.java
----------
This java class demonstrates inserting 500,000 rows into a table, one row at
a time. With just a single commit at the end of the entire job.
Auto-commit is switched off.
Bind variables are used for the insert statements. This reduces parsing effort.
You will need to change a few constants (database name, schema owner, etc.) before
running this program in your environment. See the code below for details.
compile using:
set CLASSPATH=.;C:oracleora81jdbclibclasses111.zip
javac test3.java
Written: 18/10/01, Dave Wotton
For more information about this test, including results and conclusions,
refer to http://home.clara.net/dwotton/dba/java_insert.htm
*/
import java.io.*;
import java.sql.*;
import java.util.*;
import java.text.*;
public class test3
{
public static void main (String[] args) throws SQLException
{
int recCount = 0;
String record = null;
// You will need to make the following substitutions before running the program:
//
// server_ipname -> the IP name of your Oracle server
// oracle_sid -> the SID of your Oracle instance
// Login -> the owner of the schema holding the dave_test1 table
// Password -> the schema owner's password.
String connect_string = "jdbc:oracle:thin:@server_ipname:1521:oracle_sid";
String Login = "scott";
String Password = "tiger";
// create a Date variable ...
java.util.Date now = new java.util.Date();
// Define a dateformatter to display date variables ...
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.DEFAULT);
// Timestamp the start of the run ...
long startTime = System.currentTimeMillis();
// convert the startTime into Date format
now.setTime(startTime);
// and display the start of run stats
System.out.println("Time now: " + df.format(now) );
// Load Oracle driver ...
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
// Connect to the database ...
Connection conn =
DriverManager.getConnection (connect_string, Login, Password );
// Disable auto-commit ...
conn.setAutoCommit (false);
try {
// define a buffered reader, connected to the file "dave_test.in" ...
FileReader fr = new FileReader("dave_test.in");
BufferedReader br = new BufferedReader(fr);
// define a string to hold the records returned by the buffered reader ...
record = new String();
// Prepare an Oracle statement (with bind variables) to perform the update ...
PreparedStatement pstmt =
conn.prepareStatement ("insert into dave_test1 values(?,?,?,?)" );
// Do the real processing ...
// ----------------------
while ((record = br.readLine()) != null)
{
recCount++;
// define a tokenizer to split the input record into fields, using ':' as
// the delimiter.
StringTokenizer st = new StringTokenizer(record, ":");
String l_key = st.nextToken(); // an integer
String l_col1 = st.nextToken(); // a small word
String l_col2 = st.nextToken(); // a digit in the range 0-6
String l_col3 = st.nextToken(); // a long string
// and insert the row into the database ...
pstmt.setInt(1,Integer.parseInt( l_key.trim() ) );
pstmt.setString(2,l_col1.trim() );
pstmt.setInt(3,Integer.parseInt( l_col2.trim() ) );
pstmt.setString(4,l_col3.trim() );
pstmt.executeUpdate (); // Do the update
// if ( recCount > 100 ) { break; }
}
Statement stmt = conn.createStatement ();
stmt.executeQuery ("commit");
pstmt.close(); // close the prepared statement object used for the inserts
stmt.close(); // close the statement object used for the commit
conn.close(); // close the database connection
// Timestamp the end of the run ...
long stopTime = System.currentTimeMillis();
// Calculate the duration ...
long runTime = stopTime - startTime;
// convert to mm:ss ...
long mins = runTime / 60000;
long secs = ( runTime % 60000 ) / 1000;
String mins_str = mins + "" ;
if ( mins_str.length() == 1 ) { mins_str = '0' + mins_str; }
String secs_str = secs + "";
if ( secs_str.length() == 1 ) { secs_str = '0' + secs_str; }
String Duration = mins_str + ":" + secs_str;
// convert the stopTime into Date format
now.setTime(stopTime);
// and display the end of run stats
System.out.println("Time now: " + df.format(now) + " Run time: " + runTime + "ms (" + Duration + ")" );
} catch (IOException e) {
// catch possible io errors from readLine()
System.out.println("Uh oh, got an IOException error!");
e.printStackTrace();
}
} // end of main
} // end of class
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
18 | Applet 에서 JavaScript 를 호출 | 박상현 | 2003.10.13 | 2414 |
17 | 색상표 | 박상현 | 2003.10.10 | 1771 |
16 | [javascript]textarea의 내용을 클립보드에 담아 처리하기 | 박상현 | 2003.10.09 | 3679 |
15 | [제로보드] 일반페이지 인증하기 | 박상현 | 2003.10.09 | 1967 |
14 | 시간안에 응답하지 않는함수는 에러(혹은 exception)처리 | 박상현 | 2003.10.08 | 2046 |
13 | 자바스크립트사용시 주의점 | 운영자 | 2003.10.06 | 1899 |
12 | excel로 자료 출력 | 운영자 | 2003.10.06 | 2387 |
» | batch 작업 | 박상현 | 2002.02.13 | 2020 |
10 | 수정된 StringTokenizer | 박상현 | 2001.12.17 | 2579 |
9 | java에서 system의 property확인 jsp파일 | 박상현 | 2001.10.27 | 2358 |
8 | 프리페어스테이트먼트에 ? 표 자리에 값을 셋팅후 만들어진 SQL 문을 보는 유틸 | 운영자 | 2003.09.18 | 3391 |
7 | RAS암호 시스템의 구현 | 박상현 | 2001.10.16 | 3232 |
6 | JCE정보 보는 소스 | 박상현 | 2001.10.16 | 2399 |
5 | 테두리및 가로줄, 세로줄이 1px인 테이블 만들기 | 운영자 | 2003.10.01 | 2531 |
4 | table 외곽에 테두리만 1pixel로 만들기 | 운영자 | 2003.10.01 | 2249 |
3 | BB설명 | 운영자 | 2003.09.26 | 2159 |
2 | 창닫기 전에 물어보기 | 운영자 | 2003.09.26 | 2574 |
1 | popup창 띄우는 4가지 방법 | 운영자 | 2003.09.24 | 4004 |