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(); } } }
配置文件
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