发表于: 2019-10-15 23:42:42

1 884


今天完成的事情:


今天的学习状态不好,学了一天

都不知道自己学了啥


1.  jdbctemplate     总失败


applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

   <!--自动扫描包,此处 com.tuck.jdbc 改成自己实际项目包路径-->
   <!--扫描 com.ordust 包及子包中所有的组件类-->
   <context:component-scan base-package="com.ordust"/>

   <!--导入资源文件-->
   <context:property-placeholder location="classpath:db.properties"/>

   <!--配置 c3p0 数据源-->
   <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
       <property name="user" value="${jdbc.user}"/>
       <property name="password" value="${jdbc.password}"/>
       <property name="jdbcUrl" value="${jdbc.jdbcUrl}"/>
       <property name="driverClass" value="${jdbc.driverClass}"/>

       <property name="initialPoolSize" value="${jdbc.initPoolSize}"/>
       <property name="maxPoolSize" value="${jdbc.maxPoolSize}"/>
   </bean>

   <!-- 配置 spring JdbcTemplate -->
   <bean id="jdbcTemplate"
         class="org.springframework.jdbc.core.JdbcTemplate">
       <property name="dataSource" ref="dataSource"></property>
   </bean>

   <!--配置事务管理器-->
   <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
       <property name="dataSource" ref="dataSource"></property>
   </bean>

   <!--启用事务注解-->
   <tx:annotation-driven/>
</beans>

db.properties

jdbc.user=root
jdbc.password=123456
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/student?characterEncoding=UTF-8
jdbc.initPoolSize=5
jdbc.maxPoolSize=10

一个实体类   后面太长就不截取了


接下来是测试 ,老出问题 


public class StudentTest {
private JdbcTemplate jdbcTemplate;
   private ApplicationContext context = null;

   //初始化连接池
   {
context = new ClassPathXmlApplicationContext("applicationContext.xml");
       jdbcTemplate = (JdbcTemplate) context.getBean("jdbcTemplate");
   }

//测试是否连接数据库
   @Test
   public void testIsConnect() throws SQLException {
DataSource dataSource = context.getBean(DataSource.class);
       System.out.println("连接成功"+dataSource.getConnection());
   }
}


报错信息   很多  不知道重点看哪   师兄说我写了个死锁  apparent deadlock


今天还整理了下   jdbctemplate需要的文件


1.一个实体类文件’

2.配置文件  

db.properties属性文件

applicationContext.xml文件

3.测试类文件

4.一个dao文件  接口文件  封装对某个对象的增删查改操作


2. 找到了一个师兄整理的   任务1的全部所需学习资料

https://www.jianshu.com/p/00003f8a980e

东西很有用


不过  自己没有目标的瞎翻看了下  浪费了一些时间


其他时间    是碰到一些不懂的词的就百度看了下  

然后还没深入看懂  只是了解。



明天计划的事情:


重新创建一个新的maven文件,新的数据库   

再试试连接jdbctemplate


遇到的问题:


学习方法有问题了,没有计划


收获:



返回列表 返回列表
评论

    分享到