• spring-jdbc5新特性,一个配置文件解决临时修改数据库的问题


    import java.sql.SQLException;
    import java.util.List;
    import java.util.Map;
    
    import javax.sql.DataSource;
    
    import org.apache.commons.io.FilenameUtils;
    import org.springframework.jdbc.core.JdbcTemplate;
    
    import com.alibaba.fastjson.JSONArray;
    import com.zaxxer.hikari.HikariDataSource;
    
    public class UpdataGbrecUtil {
    
        public static void main(String[] args) {
    
            String path=Thread.currentThread().getContextClassLoader().getResource("hikariCP.properties").getPath();
            path=FilenameUtils.separatorsToUnix(path);
            System.setProperty("hikaricp.configurationFile", path);
            DataSource ds = new HikariDataSource();
            try {
                System.out.println(ds.getConnection());
                JdbcTemplate jdbc = new JdbcTemplate(ds);
                List<Map<String, Object>> data = jdbc.queryForList("select * from sheet1 ");
                JSONArray arr=(JSONArray) JSONArray.toJSON(data);
                System.out.println(arr.toString());
            } catch (SQLException e) {
                e.printStackTrace();
            }
    
        }
    }
    View Code

    配置文件

     1 username=
     2 password=
     3 maximumPoolSize=30
     4 minimumIdle=5
     5 connectionTestQuery=SELECT 1
     6 autoCommit=true
     7 dataSource.cachePrepStmts=true
     8 dataSource.prepStmtCacheSize=250
     9 dataSource.prepStmtCacheSqlLimit=2048
    10 dataSource.useServerPrepStmts=true
    11 dataSource.useLocalSessionState=true
    12 dataSource.useLocalTransactionState=true
    13 dataSource.rewriteBatchedStatements=true
    14 dataSource.cacheResultSetMetadata=true
    15 dataSource.cacheServerConfiguration=true
    16 dataSource.elideSetAutoCommits=true
    17 dataSource.maintainTimeStats=false
    18 #driverClassName=com.mysql.jdbc.Driver
    19 driverClassName=org.sqlite.JDBC
    20 #jdbcUrl=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=true
    21 jdbcUrl=jdbc:sqlite:///C:/Users/Administrator/Desktop/tmp/gbrec.db
    View Code
  • 相关阅读:
    bind(),live(),delegate(),on()绑定事件方式
    3 《锋利的jQuery》jQuery中的DOM操作
    表格功能
    5.2 《锋利的jQuery》jQuery对表格的操作(选项卡/换肤)
    4.1 《锋利的jQuery》jQuery中的事件
    5.1 《锋利的jQuery》jQuery对表单的操作
    4.2 《锋利的jQuery》jQuery中的动画
    2 《锋利的jQuery》jQuery选择器
    回流(reflow)与重绘(repaint)
    BOX2d绘制曲线
  • 原文地址:https://www.cnblogs.com/swtjavaspace/p/9761063.html
Copyright © 2020-2023  润新知