发表于: 2022-05-09 19:03:54
1 485
在idea当中循环了一百万次数据:
public static void main(String[] args) {
//上下文取连接池jdbc
ApplicationContext context =
new ClassPathXmlApplicationContext("applicationContext.xml");
JdbcTemplate jdbcTemplate = (JdbcTemplate) context.getBean("jdbcTemplate");
context = new ClassPathXmlApplicationContext("applicationContext.xml");
ComboPooledDataSource ds2 = (ComboPooledDataSource) context.getBean("dataSource");
//无连接池jdbc
// DriverManagerDataSource ds = new DriverManagerDataSource ();
// ds.setDriverClassName("com.mysql.jdbc.Driver");
// ds.setUrl("jdbc:mysql://localhost:3306/fc");
// ds.setUsername("root");
// ds.setPassword("adbrk");
jdbcTemplate = new JdbcTemplate(ds2);
String sql = "select id,name,school,type,time,student,make_a_wish from biage";
System.out.println(jdbcTemplate.queryForList(sql));
for (Map<String, Object> stringObjectMap : jdbcTemplate.queryForList(sql)) {
System.out.println(stringObjectMap);
}
//将数据库查询结果转换为Java
for (int i = 0; i < 1000000; i++) {
//查询mysql数据库下Biage的所有记录
List<Biage> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Biage.class));
// System.out.println("id是" + biage.getId());
for (Biage biage : list) {
System.out.println("id是" + biage.getId());
定义一个时间戳:
Timestamp timestamp2 = new Timestamp(System.currentTimeMillis());
System.out.println("开始"+ timestamp);
System.out.println("结束"+ timestamp2);
定义值:
public class Biage implements Serializable {
private static final long serialVersionUID = -7850272141987310060L;
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;}
执行之后的开始到结束的所需的时间:
开始2022-05-09 13:55:44.939
结束2022-05-09 13:58:50.022
Process finished with exit code 0
遇到的问题,添加时间戳时候,因为数据太长,最前面的时间不显示。
解决方法:将时间变量在前面声明,最后输出:
public static void main(String[] args) {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
Timestamp timestamp2 = new Timestamp(System.currentTimeMillis());
System.out.println("开始"+ timestamp);
System.out.println("结束"+ timestamp2);
今天学习到了新的代码,时间戳:
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
System.out.println(timestamp);
今天的问题:想插入数据,但是弄错成查询数据了。
明天计划:将插入语句完成,插入100万条代码查看有无索引的区别。
评论