阿帕奇官网:http://poi.apache.org/

POI3.17下载:http://poi.apache.org/download.html#POI-3.17

POI操作Excel教程(易百教程):https://www.yiibai.com/apache_poi/

1.数据库连接:https://www.cnblogs.com/feipengting/p/7606042.html

 1 package com.gdin.util;
 2 
 3 import java.io.InputStream;
 4 import java.sql.Connection;
 5 import java.sql.DriverManager;
 6 import java.sql.PreparedStatement;
 7 import java.sql.ResultSet;
 8 import java.sql.SQLException;
 9 import java.sql.Statement;
10 import java.util.Properties;
11 
12 public class DBUtil {
13 
14      private static Connection con;
15         private static String url;
16         private static String user;
17         private static String pwd;
18 
19         public DBUtil() {
20 
21         }
22         static {
23             try {
24                 Class.forName("oracle.jdbc.driver.OracleDriver");/*如果是MySQL就改为Class.forName("com.mysql.jdbc.Driver");*/
25                 InputStream is = DBUtil.class.getResourceAsStream("/db.properties");//db.properties 是一个用户配置文件传用户名密码
26                 Properties prop=new Properties();
27                 prop.load(is);
28                 url=prop.getProperty("url");
29                 user=prop.getProperty("user");
30                 pwd=prop.getProperty("password");
31                 con = DriverManager.getConnection(url, user, pwd);
32             }catch (Exception e){
33                 System.out.println("数据库连接失败!");
34             }
35         }
36         public static ResultSet find(String sql){
37             con=getCon();
38             try {
39                 Statement smt=con.createStatement();
40                 ResultSet rs=smt.executeQuery(sql);
41                 return rs;
42             } catch (SQLException e) {
43                 e.printStackTrace();
44                 return null;
45             }
46         }
47         public static ResultSet find(String sql,Object ...pram){//...pram数组
48             con=getCon();
49             try {
50                 PreparedStatement smt=con.prepareStatement(sql);
51                 for (int i=0;i<pram.length;i++){
52                     smt.setObject(i+1,pram[i]);
53                 }
54                 ResultSet rs=smt.executeQuery();
55                 return rs;
56             } catch (SQLException e) {
57                 e.printStackTrace();
58                 return null;
59             }
60         }
61         public static void insert(String sql,Object ...pram){//...pram数组
62             con=getCon();
63             try {
64                 PreparedStatement smt=con.prepareStatement(sql);
65                 for (int i=0;i<pram.length;i++){
66                     smt.setObject(i+1,pram[i]);
67                 }
68                 smt.executeUpdate();
69             } catch (SQLException e) {
70                 e.printStackTrace();
71             }
72         }
73         public static Connection getCon(){
74             try {
75                 if(con==null||con.isClosed())
76                     con = DriverManager.getConnection(url, user, pwd);
77             } catch (SQLException e) {
78                 e.printStackTrace();
79             }
80             return con;
81         }
82 }
View Code

相关文章: