应用场景:
测试索引对查找速度的影响
package com.dlj.test;
import java.sql.PreparedStatement;
import java.util.UUID;
import com.dlj.utils.DBUtil;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class UuidTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection connection = null;
PreparedStatement preparedStatement = null;
//根据目标表中所包含的字段,准备sql
String sql = "insert into t_uuid(uuid, create_time, update_time) values (?, now(), now())";
try {
connection = (Connection) DBUtil.getConnection();
preparedStatement = connection.prepareStatement(sql);
//利用for循环控制添加记录的条数
for (int i = 0; i < 1000000; i++) {
String uuid = UUID.randomUUID().toString();//获取UUID
System.out.println(uuid);
preparedStatement.setString(1, uuid);
//执行sql
boolean success = preparedStatement.execute();
//打印执行结果
System.out.println("执行结果:" + success);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally {
DBUtil.close(connection, preparedStatement, null);
}
}
}