Java 学习笔记07:使用Spring的Dao连接数据库
关于DAO
DAO组件是整个java应用的吃就成访问的重要组件,Dao模式的主要内容为:应用中所有对数据库的访问都通过Dao组件完成,Dao组件封装了对数据库的增、删、改、查等操作。具体实现
创建一个新的项目地址,名称为Spring
既然是数据库操作,肯定要有数据库配置,创建一个jdbc.properties的文件,放置在src/目录下,里面包含数据库连接的重要信息。
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql://127.0.0.1:3306/test
jdbc.username = root
jdbc.password = root
创建一个bean.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
- java教程,自学编程,青软培训