设为首页 加入收藏

TOP

Spring对JDBC的模板支持:JdbcTemplate(二)
2018-03-18 16:21:49 】 浏览:673
Tags:Spring JDBC 模板 支持 JdbcTemplate
p;     <artifactId>spring-jdbc</artifactId>
            <version>4.3.14.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.39</version>
        </dependency>
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.5.2</version>
        </dependency>
    </dependencies>


使用JdbcTemplate的基本步骤:


<?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:p="http://www.springframework.org/schema/p"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      ">


    <context:annotation-config/>
    <context:component-scan base-package="org.zero01"/>


    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
          p:driverClass="com.mysql.jdbc.Driver"
          p:jdbcUrl="jdbc:mysql:///school"
          p:user="root"
          p:password="Zero-One1."
          p:loginTimeout="2000"
          p:maxPoolSize="10"
          p:minPoolSize="1"
    />
</beans>


package org.zero01.pojo;


import org.springframework.stereotype.Component;


@(JavaWeb)Component("stu")
public class Student {


    private int sid;
    private String name;
    private int age;
    private String sex;
    private String address;


    public int getSid() {
        return sid;
    }


    public void setSid(int sid) {
        this.sid = sid;
    }


    public String getName() {
        return name;
    }


    public void setName(String name) {
        this.name = name;
    }


    public int getAge() {
        return age;
    }


    public void

首页 上一页 1 2 3 4 5 下一页 尾页 2/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Web正面临威胁,请加入我们为之奋.. 下一篇使用Java内置类HttpUrlConnection..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目