1.
1 package com.asm;
2
3 import java.io.File;
4 import java.io.InputStream;
5 import java.sql.Connection;
6 import java.sql.DriverManager;
7 import java.sql.ResultSet;
8 import java.sql.Statement;
9
10 import org.junit.Test;
11 import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;
12 import org.springframework.test.context.TestExecutionListeners;
13
14 public class TestProxool {
15     public static String dburl = "jdbc:mysql://localhost:3306/test";
16     public static String user = "root";
17     public static String password = "123456";
18
19     /**
20      *   /**   * JDBC方式测试   *   * @throws Exception
21      */
22     @Test
23     public void test() throws Exception {
24         String testsql = "select * from village t where lastid = 1";
25         // 1:注册驱动类
26         Class.forName("com.mysql.jdbc.Driver");
27         // 2:创建数据库连接
28         Connection conn = DriverManager.getConnection(dburl, user, password);
29         // 3:创建执行SQL的对象
30         Statement stmt = conn.createStatement();
31         // 4:执行SQL,并获取返回结果
32         ResultSet rs = stmt.executeQuery(testsql);
33         // 5:处理返回结果,此处打印查询结果
34         while (rs.next()) {
35             System.out.print(rs.getLong("lastid") + " ");
36             System.out.print(rs.getString("lastname") + " ");
37             System.out.println();
38         }
39         // 6:关闭数据库连接
40         conn.close();
41     }
42
43     /**
44      *   * proxool方式测试   *   * @throws Exception
45      */
46     @Test
47     public  void test2() throws Exception {
48         //Java应用中先要加载配置文件,否则谁知道你配置给谁用的
49         JAXPConfigurator.configure("F:\hysworkspace1\ProxoolTest\src\proxool.xml", false);
50         String testsql = "select * from village t where lastid = 1";
51         //1:注册驱动类,这次这个驱动已经不是Oracle的驱动了,是Proxool专用的驱动
52         Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
53         //2:创建数据库连接,这个参数是一个字符串,是数据源的别名,在配置文件中配置的timalias,参数格式为:proxool.数据源的别名
54         Connection conn = DriverManager.getConnection("proxool.timalias");
55         //3:创建执行SQL的对象
56         Statement stmt = conn.createStatement();
57         //4:执行SQL,并获取返回结果
58         ResultSet rs = stmt.executeQuery(testsql);
59         //5:处理返回结果,此处打印查询结果
60         while (rs.next()) {
61             System.out.print(rs.getLong("lastid") + " ");
62             System.out.print(rs.getString("lastname") + " ");
63         System.out.println();
64         }
65         //6:关闭数据库连接
66         conn.close();
67     }
68 }