发表于: 2022-05-10 18:28:24

1 342



遇到的问题1:Cannot resolve method 'update' in 'jdbcTemplate'


解决方法:在idea的setteings当中下载lombok插件


之后file----> 重启idea


添加变量:

package test;

public class jdbcTemplate {
public int update(String sql, int age, int id, String name) {
return 0;
   }

public int update(String sql, Object[] args) {
return 0;
   }
}


问题解决:

public class Test01DaoImpl implements Test01Dao {

//注入jdbcTemplate对象
   @Autowired
   private test.jdbcTemplate jdbcTemplate;

   //添加的方法,从实体类Test01中传递对象进来
   @Override
   public void add(Test01 test01) {

String sql = "insert into test01 values(?,?,?)";

//        int update = jdbcTemplate.update(sql, test01.getAge(), test01.getId(), test01.getName());


       //可以变式为
       Object[] args= {test01.getName(), test01.getId(),test01.getAge()};
    int update = jdbcTemplate.update(sql,args);

       //输出影响的值
       System.out.println(update);



问题2:插入代码时输入的顺序排列错误:

Object[] args= {test01.getName(), test01.getId(),test01.getAge()};
int update = jdbcTemplate.update(sql,args);



解决方法:手动将它的顺序自定义:

String sql = "insert into test01 (name,id,age) values(?,?,?)";



问题3:Error creating bean with name 'Test01Dao'


解决方法:将赋值的地址带入bean中


<bean id="test01Service" class="com.dao.Test01DaoImpl"/>
Test01DaoImpl test01Service = context.getBean("test01Service",Test01DaoImpl.class);


插入一百万条数据:


public class TestTest01 {
public static void  main(String[] args){
Timestamp timestamp = new Timestamp(System.currentTimeMillis());

       ApplicationContext context =
new ClassPathXmlApplicationContext("applicationContext.xml");

       Test01DaoImpl test01Service = context.getBean("test01Service",Test01DaoImpl.class);

       Test01 t1 = new Test01();

       for (int i = 0; i < 1000000; i++) {

t1.setName("张三");
           t1.setAge(20);

           test01Service.add(t1);

      }

Timestamp timestamp2 = new Timestamp(System.currentTimeMillis());
       System.out.println("开始"+ timestamp);
       System.out.println("结束"+ timestamp2);

   }
}


执行消耗的时间:




查询插入了的数据:






插入了5000万条数据之后加入索引:





有索引的搜索所耗的时间:







删除索引后所耗的时间:








有无索引在数据量大的情况下,有着明显的变化。






明天计划:将任务一回顾总结一下。













返回列表 返回列表
评论

    分享到