zoukankan      html  css  js  c++  java
  • Spring数据库连接池

    创建JDBC.properties,里面写连接数据库需要的4个值

    jdbc.user=root
    jdbc.password=123456
    jdbc.driver=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://localhost:3306/lhw

    applicationContext中的配置

    <bean id="comboPooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
         <property name="user" value="${jdbc.user}"></property>
         <property name="password" value="${jdbc.password}"></property>
         <property name="driverClass" value="${jdbc.driver}"></property>
           <property name="jdbcUrl" value="${jdbc.url}"></property>
      </bean>
    View Code

    简单的查询数据

    public void test() throws SQLException {
            ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
            DataSource dataSource = ac.getBean(DataSource.class);
            Connection con = dataSource.getConnection();
            String sql="select * from student";
            PreparedStatement ps = con.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while(rs.next()){
                String name = rs.getString("name");
                String school = rs.getString("school");
                double score = rs.getDouble("score");
                System.out.println(name+school+score);
            }
        }
    View Code
  • 相关阅读:
    linux读写锁
    正则表达式
    C++原型模式和模板模式
    C++外观模式和组合模式
    C++代理模式
    c++桥接模式
    Linux常用命令history/tcpdump/awk/grep
    C++委托模式
    c++ 读写锁
    布衣客
  • 原文地址:https://www.cnblogs.com/Ysuwade/p/7445543.html
Copyright © 2011-2022 走看看