美文网首页
spring jdbc配置

spring jdbc配置

作者: wangpeng123 | 来源:发表于2018-04-25 17:46 被阅读0次

    maven:

    <dependency>
                <groupId>org.springframework</groupId>
                <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>
    

    xml:

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://127.0.0.1:3306/database"/>
            <property name="username" value="name"/>
            <property name="password" value="passowrd"/>
        </bean>
    
        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource" ref="dataSource"/>
        </bean>
    

    java:

    jdbcTemplate.queryForList("select DISTINCT(day) from table order by day desc", String.class);
    

    相关文章

      网友评论

          本文标题:spring jdbc配置

          本文链接:https://www.haomeiwen.com/subject/ygrrqftx.html