當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring JDBC 框架,我的学习笔记
生活随笔
收集整理的這篇文章主要介紹了
Spring JDBC 框架,我的学习笔记
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Student.java:
StudentDAO: 一個接口
setDataSource方法注入javax.sql.DataSource的依賴:
StudentMapper: java.sql.ResultSet包含的是單條記錄:
StudentJDBCTemplate: 是接口StudentDAO的實現類。關鍵就是setDataSource方法,需要研究其是何時被調用的。DataSource被注入之后,基于這個注入的DataSource創建jdbcTemplateObject實例。
Java代碼里的data source和MySQL服務器實例的綁定關系在beans.xml里維護:
Beans.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" xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd "><!-- Initialization for data source --><bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"/><property name="url" value="jdbc:mysql://localhost:3306/TEST"/><property name="username" value="root"/><property name="password" value="123456"/></bean><!-- Definition for studentJDBCTemplate bean --><bean id="studentJDBCTemplate" class="com.sap.StudentJDBCTemplate"><property name="dataSource" ref="dataSource" /> </bean></beans>要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
總結
以上是生活随笔為你收集整理的Spring JDBC 框架,我的学习笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何在MySQL中创建存储过程
- 下一篇: 使用JavaScript遍历本地文件夹的