新建java project,名称为ProxoolTest,在根目录下新建src文件夹,并在src文件夹下新建test类和proxool.xml文件
- //test.java文件
- package src;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import org.logicalcobwebs.proxool.ProxoolException;
- import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;
- public class test {
- /**
- * @param proxool方式
- * @throws ProxoolException
- * @throws ClassNotFoundException
- */
- public static void main(String[] args) throws Exception {
- Connection conn =null;
- Statement stmt = null;
- ResultSet rs = null;
- try {
- System.out.println(test.class.getResource("/").toString());
- System.out.println(test.class.getResource("/").getPath().toString());
- //Java应用中先要加载配置文件,否则谁知道你配置给谁用的 以下两种方式都可以
- //JAXPConfigurator.configure("D://TempWorkSpace//ProxoolTest//"+"src//proxool.xml", false); //绝对路径方式
- JAXPConfigurator.configure(test.class.getResource("/").toString().substring(6)+"src//proxool.xml", false); //相对路径方式
- String testsql = "select * from tbarea ";
- //1:注册驱动类,这次这个驱动已经不是Oracle的驱动了,是Proxool专用的驱动
- Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
- //2:创建数据库连接,这个参数是一个字符串,是数据源的别名,在配置文件中配置的timalias,参数格式为:proxool.数据源的别名
- conn = DriverManager.getConnection("proxool.mysql");
- //3:创建执行SQL的对象
- stmt = conn.createStatement();
- //4:执行SQL,并获取返回结果
- rs = stmt.executeQuery(testsql);
- //5:处理返回结果,此处打印查询结果
- while (rs.next()) {
- System.out.print(rs.getLong("areaid") + "/t");
- System.out.print(rs.getString("areaname") + "/t");
- System.out.println();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }finally{
- try {
- if(rs!=null) rs.close();
- if(stmt!=null) stmt.close();
- //6:关闭数据库连接
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- /**
- * JDBC方式测试
- *
- * @throws Exception
- */
- public static void test1() throws Exception {
- String dburl = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=TestDB";
- String user = "sa";
- String password = "sa";
- String testsql = "select * from tbarea";
- //1:注册驱动类
- Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
- //2:创建数据库连接
- Connection conn = DriverManager.getConnection(dburl, user, password);
- //3:创建执行SQL的对象
- Statement stmt = conn.createStatement();
- //4:执行SQL,并获取返回结果
- ResultSet rs = stmt.executeQuery(testsql);
- //5:处理返回结果,此处打印查询结果
- while (rs.next()) {
- System.out.print(rs.getLong("areaid") + "/t");
- System.out.print(rs.getString("areaname") + "/t");
- System.out.println();
- }
- //6:关闭数据库连接
- conn.close();
- }
- }
我的测试文档:
- <!-- proxool.xml 文件 -->
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <!--</SPAN><SPAN style="COLOR: #008000" mce_style="COLOR: #008000"> the proxool configuration can be embedded within your own application's.<BR><IMG src="/Images/OutliningIndicators/None.gif" mce_src="Images/OutliningIndicators/None.gif" align=top>Anything outside the "proxool" tag is ignored. </SPAN><SPAN style="COLOR: #008000" mce_style="COLOR: #008000">-->
- <something-else-entirely>
- <proxool>
- <alias>mysql</alias>
- <driver-url>jdbc:sqlserver://127.0.0.1:1433;DatabaseName=TestDB</driver-url>
- <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
- <driver-properties>
- <property name="user" value="sa"/>
- <property name="password" value="sa"/>
- </driver-properties>
- <maximum-connection-count>100</maximum-connection-count>
- <house-keeping-sleep-time>30000</house-keeping-sleep-time>
- <prototype-count>15</prototype-count>
- <minimum-connection-count>5</minimum-connection-count>
- <!--prototype-count>4</prototype-count-->
- <maximum-active-time>100</maximum-active-time>
- <house-keeping-test-sql>select * from tbUsers</house-keeping-test-sql>
- </proxool>
- </something-else-entirely>
- package cn.cstnet.cstnms.config.util;
//package cn.cstnet.cstnms.report.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.logicalcobwebs.proxool.ProxoolException;
import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;
public class proxoolTest {
/**
* @param proxool方式
* @throws ProxoolException
* @throws ClassNotFoundException
*/
public static void main(String[] args) throws Exception {
Connection conn =null;
Statement stmt = null;
ResultSet rs = null;
try {
// System.out.println(test.class.getResource("/").toString());
// System.out.println(test.class.getResource("/").getPath().toString());
//Java应用中先要加载配置文件,否则谁知道你配置给谁用的 以下两种方式都可以
//JAXPConfigurator.configure("D://TempWorkSpace//ProxoolTest//"+"src//proxool.xml", false); //绝对路径方式
JAXPConfigurator.configure("d:/eclipse-flex/eclipse/workspace/ITraffic/WebContent/WEB-INF/proxool.xml", false); //相对路径方式
String testsql = "select * from fys ";
//1:注册驱动类,这次这个驱动已经不是Oracle的驱动了,是Proxool专用的驱动
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
//2:创建数据库连接,这个参数是一个字符串,是数据源的别名,在配置文件中配置的timalias,参数格式为:proxool.数据源的别名
conn = DriverManager.getConnection("proxool.report_cfg_8_104");
//3:创建执行SQL的对象
stmt = conn.createStatement();
//4:执行SQL,并获取返回结果
rs = stmt.executeQuery(testsql);
//5:处理返回结果,此处打印查询结果
while (rs.next()) {
System.out.print(rs.getLong("id") + "/t");
System.out.print(rs.getString("fy_name") + "/t");
System.out.println();
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
if(rs!=null) rs.close();
if(stmt!=null) stmt.close();
//6:关闭数据库连接
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}