\src\JDBCUtils.ini
url=jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai username=root password=123456\src\com\data\entity\Mysql_Template_conn.java
package com.data.entity; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DriverManagerDataSource; import javax.sql.DataSource; import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.Properties; /* JDBC Mysql_Template 封装增删改查 *QQ 7650371 * */ public class Mysql_Template_conn { public static final DataSource dataSource; static { //静态代码块 Properties props = new Properties(); //jdbc.properties"try(InputStream in = JdbcTemplate.class.getResourceAsStream("/JDBCUtils.ini")){ props.load(in); } catch (IOException e) { throw new RuntimeException(e); } String url = props.getProperty("url"); String username = props.getProperty("username"); String password = props.getProperty("password"); dataSource = new DriverManagerDataSource(url,username,password); } public Mysql_Template_conn() {} public static DataSource getCon() { return dataSource; } public static JdbcTemplate newJdbcTemplate() { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); return jdbcTemplate; } public static int update(String sql,Object... args){ //动态参数 可以增删改,但是不能查询 try { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); return jdbcTemplate.update(sql,args); //添加 } catch (Exception e) { System.out.println(e.toString()); return 0; } } //public void executeQuery(String sql) { // try { // JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); // List