@echo off
cls
set CLASSPATH=../api/jogre.jar
set CLASSPATH=%CLASSPATH%;.
set CLASSPATH=%CLASSPATH%;classes
set CLASSPATH=%CLASSPATH%;lib/dom4j.jar
java org.jogre.server.JogreServer
Create table
Copy the code code as follows:
create database con_test;
use con_test;
create table test(id int not null,txt varchar (70),primary key (id),index (id));
Just two fields, id plus index.
Use a java program to loop through the table 100,000 times to insert records, id (number of loops) and content (this record is the =xx)
InsertTestMysql.java
Copy the code code as follows:
import java.lang.*;
import java.sql.*;
public class InsertTestMysql{
public static void main(String [] args){
java.util.Date now_start = new java.util.Date();
long start_time=now_start.getTime();
int st = 100000;
String str,info;
String db="org.gjt.mm.mysql.Driver";
String host="jdbc:mysql://192.168.1.35/test";
String user="root";
String passwd="root";
Connection con=null;
try{
Class.forName(db).newInstance();
}
catch(Exception e){
System.out.println("Loading driver failed:"+db);
}
try{
con=DriverManager.getConnection(host,user,passwd);
con.setAutoCommit(false);//Turn off automatic transaction submission
for (int i=1;i<=st;i++){
info = "This record is the =";
info = info.concat(java.lang.Integer.toString(i));
str = "insert into test (id,txt) values(?,?);";
PreparedStatement pstmt = con.prepareStatement(str);
pstmt.setInt(1,i);
pstmt.setString(2,info);
pstmt.executeUpdate();
}
con.commit();//After the statement is executed, submit this transaction
con.close();
}
catch(Exception e) {
System.out.println(e);
}
java.util.Date now_end = new java.util.Date();
long end_time=now_end.getTime();
long use_time=end_time-start_time;
System.out.println("<<---The generation of this page took ["+use_time+"] milliseconds ("+((double)use_time)/1000+" seconds)--->>");
System.out.println("/n<<---A total of inserted records "+st+"-->>");
}
}
The performance is different under different versions of jdbc.
jdbc 3.1.7, 12770,12778 When this number is inserted, the program exits and the Chinese language is normal.
jdbc 3.1.12 12000 When this number is inserted, the program exits and Chinese is normal.
The following prompts appear:
"Exception in thread "main" java.lang.OutOfMemoryError: Java heap space"
"Java Heap Space Error" may be because my machine does not have enough memory. But it's normal when using 3.10 series jdbc.
jdbc 3.0.16-ga 100,000 records are normal and Chinese is normal.
jdbc 3.0.10 successfully recorded 100,000 records, but had Chinese errors.
Using 3.1 series jdbc, after the program is run, the remaining physical memory of the machine quickly becomes 40xxKB.
This may be because the jdbc3.1 series requires large memory, and my machine has insufficient memory.
I will test it on my classmate's AMD64 512M RAM machine tomorrow.
jdbc 3.0.16-ga is the only one that is normal. The test results are:
Copy the code code as follows:
D:/Program Files/test/db_test>java InsertTestMysql
<<---The generation of this page takes [98582] milliseconds (98.582 seconds)--->>
<<---A total of 100,000 records were inserted-->>
I tested it again a few days ago, using the open source jdts jdbc to connect to ms-sql server 2000 sp3. Others are the same as above, and the test results are terrible:
Copy the code code as follows:
D:/dev/java/src/ts/Ms-Sql>java InsertTestMssql
<<---The generation of this page took [1746681] milliseconds (1746.681 seconds)--->>
<<---A total of 100,000 records were inserted-->>
1 23Read the full text on the next page