1 <dependencies>
2 <dependency>
3 <groupId>com.alibaba</groupId>
4 <artifactId>easyexcel</artifactId>
5 <version>1.1.1</version>
6 </dependency>
7
8 <dependency>
9 <groupId>junit</groupId>
10 <artifactId>junit</artifactId>
11 <version>4.9</version>
12 </dependency>
13
14 <!-- jdbc -->
15 <dependency>
16 <groupId>commons-dbutils</groupId>
17 <artifactId>commons-dbutils</artifactId>
18 <version>1.7</version>
19 </dependency>
20
21 <dependency>
22 <groupId>com.mchange</groupId>
23 <artifactId>c3p0</artifactId>
24 <version>0.9.5.2</version>
25 </dependency>
26
27 <dependency>
28 <groupId>mysql</groupId>
29 <artifactId>mysql-connector-java</artifactId>
30 <version>5.1.40</version>
31 </dependency>
32
33 </dependencies>
工具类
1 package cn.tele.demo; 2 3 import java.sql.Connection; 4 import java.sql.ResultSet; 5 import java.sql.SQLException; 6 import java.sql.Statement; 7 import javax.sql.DataSource; 8 import com.mchange.v2.c3p0.ComboPooledDataSource; 9 10 /** 11 * 12 *@author Tele 13 * 14 */ 15 16 public class JdbcUtils { 17 private static ComboPooledDataSource dataSource = new ComboPooledDataSource(); 18 19 20 public static Connection getConnection() throws SQLException { 21 return dataSource.getConnection(); 22 } 23 24 public static DataSource getDS() { 25 return dataSource; 26 } 27 28 // 关闭数据库连接 29 public static void close(ResultSet rs, Statement stat, Connection conn) { 30 try { 31 if (rs != null) 32 rs.close(); 33 if (stat != null) 34 stat.close(); 35 if (conn != null) 36 conn.close(); 37 } catch (SQLException e) { 38 e.printStackTrace(); 39 } 40 41 } 42 43 }