MYSQL三种插入方式对比:单条插入、LOAD DATA、存储过程
2009-06-04 10:43:13 来源:WEB开发网数据源:
package com.ys.db.init;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.ys.db.init.DBProperty;
public class DataSource {
protected DataSource() {
try {
System.out.println("driverClass:" + DBProperty.driverClass);
Class.forName(DBProperty.driverClass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public Connection getConnection() {
try {
System.out.println("url:" + DBProperty.url);
System.out.println("username:" + DBProperty.username);
System.out.println("password:" + DBProperty.password);
return DriverManager.getConnection(DBProperty.url,
DBProperty.username, DBProperty.password);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
}
普通的每条插入:
以下为引用的内容:
package com.ys.db.init;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
public class TestInsert1 {
public static void main(String[] args) {
DataSource d = new DataSource();
Connection connection = d.getConnection();
try {
Statement createStatement = connection.createStatement();
long start = System.currentTimeMillis();
for (long i = 0; i < 100000; i++) {
createStatement.execute("insert into insertTB values(" + i
+ ", 'username')");
}
long end = System.currentTimeMillis();
System.out.println((end - start) / 1000);
createStatement.close();
connection.close();
// 123秒
} catch (SQLException e) {
e.printStackTrace();
}
}
}
更多精彩
赞助商链接