mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
format code
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@527 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -12,98 +12,91 @@ import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
public class DruidTest {
|
||||
|
||||
private static DruidDataSource DS;
|
||||
private static DruidDataSource DS;
|
||||
|
||||
public DruidTest(String connectURI) {
|
||||
initDS(connectURI);
|
||||
}
|
||||
public DruidTest(String connectURI){
|
||||
initDS(connectURI);
|
||||
}
|
||||
|
||||
public DruidTest(String connectURI, String username, String pswd,
|
||||
String driverClass, int initialSize, int maxActive, int maxIdle,
|
||||
int minIdle, int maxWait) {
|
||||
initDS(connectURI, username, pswd, driverClass, initialSize, maxActive,
|
||||
minIdle, maxIdle, maxWait);
|
||||
}
|
||||
public DruidTest(String connectURI, String username, String pswd, String driverClass, int initialSize,
|
||||
int maxActive, int maxIdle, int minIdle, int maxWait){
|
||||
initDS(connectURI, username, pswd, driverClass, initialSize, maxActive, minIdle, maxIdle, maxWait);
|
||||
}
|
||||
|
||||
public Connection getConn() {
|
||||
Connection con = null;
|
||||
if (DS != null) {
|
||||
try {
|
||||
con = DS.getConnection();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
public Connection getConn() {
|
||||
Connection con = null;
|
||||
if (DS != null) {
|
||||
try {
|
||||
con = DS.getConnection();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
|
||||
try {
|
||||
con.setAutoCommit(false);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return con;
|
||||
}
|
||||
return con;
|
||||
}
|
||||
try {
|
||||
con.setAutoCommit(false);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return con;
|
||||
}
|
||||
return con;
|
||||
}
|
||||
|
||||
public static void initDS(String connectURI, String username, String pswd,
|
||||
String driverClass, int initialSize, int maxActive, int maxIdle,
|
||||
int minIdle, int maxWait) {
|
||||
DruidDataSource ds = new DruidDataSource();
|
||||
ds.setDriverClassName(driverClass);
|
||||
ds.setUsername(username);
|
||||
ds.setPassword(pswd);
|
||||
ds.setUrl(connectURI);
|
||||
ds.setInitialSize(initialSize); // 初始的连接数;
|
||||
ds.setMaxActive(maxActive);
|
||||
ds.setMaxIdle(maxIdle);
|
||||
ds.setMinIdle(minIdle);
|
||||
ds.setMaxWait(maxWait);
|
||||
DS = ds;
|
||||
}
|
||||
public static void initDS(String connectURI, String username, String pswd, String driverClass, int initialSize,
|
||||
int maxActive, int maxIdle, int minIdle, int maxWait) {
|
||||
DruidDataSource ds = new DruidDataSource();
|
||||
ds.setDriverClassName(driverClass);
|
||||
ds.setUsername(username);
|
||||
ds.setPassword(pswd);
|
||||
ds.setUrl(connectURI);
|
||||
ds.setInitialSize(initialSize); // 初始的连接数;
|
||||
ds.setMaxActive(maxActive);
|
||||
ds.setMaxIdle(maxIdle);
|
||||
ds.setMinIdle(minIdle);
|
||||
ds.setMaxWait(maxWait);
|
||||
DS = ds;
|
||||
}
|
||||
|
||||
public static void initDS(String connectURI) {
|
||||
initDS(connectURI, "root", "12345", "com.mysql.jdbc.Driver", 40, 40,
|
||||
40, 10, 5);
|
||||
}
|
||||
public static void initDS(String connectURI) {
|
||||
initDS(connectURI, "root", "12345", "com.mysql.jdbc.Driver", 40, 40, 40, 10, 5);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException, SQLException {
|
||||
public static void main(String[] args) throws IOException, SQLException {
|
||||
|
||||
DruidTest db = new DruidTest("jdbc:mysql://10.20.141.150:8066/amoeba");
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
DruidTest db = new DruidTest("jdbc:mysql://10.20.141.150:8066/amoeba");
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
FileWriter fileWriter = new FileWriter("D:\\data.txt");
|
||||
try{
|
||||
conn = db.getConn();
|
||||
}catch(Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
long sum = 0;
|
||||
for (int i = 1; i < 10; i++) {
|
||||
try {
|
||||
stmt = conn.createStatement();
|
||||
Date start = new Date();
|
||||
rs = stmt
|
||||
.executeQuery("select * from offer where member_id = 'forwd251'");
|
||||
Date end = new Date();
|
||||
sum = sum + (end.getTime() - start.getTime());
|
||||
fileWriter.write(String.valueOf((end.getTime() - start
|
||||
.getTime())));
|
||||
fileWriter.write("/\n");
|
||||
FileWriter fileWriter = new FileWriter("D:\\data.txt");
|
||||
try {
|
||||
conn = db.getConn();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println((float) sum / 10);
|
||||
|
||||
|
||||
conn.close();
|
||||
stmt.close();
|
||||
rs.close();
|
||||
fileWriter.flush();
|
||||
fileWriter.close();
|
||||
}
|
||||
long sum = 0;
|
||||
for (int i = 1; i < 10; i++) {
|
||||
try {
|
||||
stmt = conn.createStatement();
|
||||
Date start = new Date();
|
||||
rs = stmt.executeQuery("select * from offer where member_id = 'forwd251'");
|
||||
Date end = new Date();
|
||||
sum = sum + (end.getTime() - start.getTime());
|
||||
fileWriter.write(String.valueOf((end.getTime() - start.getTime())));
|
||||
fileWriter.write("/\n");
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println((float) sum / 10);
|
||||
|
||||
conn.close();
|
||||
stmt.close();
|
||||
rs.close();
|
||||
fileWriter.flush();
|
||||
fileWriter.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user