1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.cy.report.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;
public class PhoenixUtil {
//创建链接
public static Connection getConnection() {
Connection conn = null;
try {
ResourceBundle b = ResourceBundle.getBundle("phoenix");
Class.forName(b.getString("driver"));
conn = DriverManager.getConnection(b.getString("url"));
conn.setAutoCommit(false);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
//执行查询语句
public static ResultSet executeQuery(String sql) {
Connection conn = getConnection();
Statement statement = null;
ResultSet rs = null;
try {
statement = conn.createStatement();
//System.out.println(sql);
rs = statement.executeQuery(sql);
// conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public static ResultSet executeQuery(String sql, Connection conn) {
Statement statement = null;
ResultSet rs = null;
try {
statement = conn.createStatement();
//System.out.println(sql);
rs = statement.executeQuery(sql);
// conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public static void main(String[] args ){
Connection connection = getConnection();
//System.out.println(connection.toString());
}
}