01: package org.huihoo.jfox.pool.connection;
02:
03: //import org.huihoo.jfox.pool.PoolManager;
04:
05: import java.sql.Connection;
06: import java.sql.ResultSet;
07: import java.sql.Statement;
08:
09: /**
10: * Created by IntelliJ IDEA.
11: * User: kelvin.wu
12: * Date: 2003-3-28
13: * Time: 16:29:06
14: * To change this template use Options | File Templates.
15: */
16: public class Test {
17: public static void main(String[] args) throws Exception {
18: SimpleConnectionPool pool = new SimpleConnectionPool(
19: "org.gjt.mm.mysql.Driver",
20: "jdbc:mysql://192.168.0.1/mysql", "root", "");
21: pool.init();
22:
23: System.out.println("Working: " + pool.getWorking());
24: System.out.println("Rest: " + pool.getRest());
25:
26: Connection conn = pool.getConnection();
27: System.out.println(conn);
28:
29: executeSQL(conn);
30: conn.close();
31:
32: // executeSQL(conn);
33: // Connection conn2 = pool.getConnection();
34: // System.out.println(conn2);
35: // Connection conn3 = pool.getConnection();
36: // System.out.println(conn3);
37: // Connection conn4 = pool.getConnection();
38: // System.out.println(conn4);
39: // Connection conn5 = pool.getConnection();
40: // System.out.println(conn5);
41: // Connection conn6 = pool.getConnection();
42: // System.out.println(conn6);
43: // Connection conn7 = pool.getConnection();
44: // System.out.println(conn7);
45: // Thread.sleep(9000);
46:
47: // ObjectPool op = PoolManager.obtainPool(new ConnectionFactory(SimplePoolableConnection.class));
48: System.out.println("Working: " + pool.getWorking());
49: System.out.println("Rest: " + pool.getRest());
50:
51: // conn7.close();
52: // System.out.println("Working: " + op.getWorking());
53: // System.out.println("Rest: " + op.getRest());
54: // conn6.close();
55: // System.out.println("Working: " + op.getWorking());
56: // System.out.println("Rest: " + op.getRest());
57: // conn5.close();
58: // System.out.println("Working: " + op.getWorking());
59: // System.out.println("Rest: " + op.getRest());
60: // conn4.close();
61: // System.out.println("Working: " + op.getWorking());
62: // System.out.println("Rest: " + op.getRest());
63: //// Statement smt = conn7.createStatement();
64: // executeSQL(conn);
65: // op.destory();
66: System.out.println(pool.getObjectFactory());
67: System.out.println(pool.getObjectClass());
68: pool.clear();
69: // System.out.println(PoolManager.existsPool(ConnectionFactory.class));
70: }
71:
72: public static void executeSQL(Connection conn) throws Exception {
73: Statement stmt = conn.createStatement();
74: ResultSet rs = stmt.executeQuery("select * from user");
75: while (rs.next()) {
76: System.out.println(rs.getString(2));
77: }
78: }
79: }
|