首页 > 代码库 > proxool的配置
proxool的配置
//依赖的包:commons-logging-api-1.1.jar,commons-logging-1.0.4.jar,proxool-0.9.1.jar,proxool-cglib.jar,cglib-nodep-2.1_3.jar,jarjar-0.6.jar,hsqldb.jar
//直接获取
public static void main(String[] args) {
try {
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
Connection conn=DriverManager.getConnection("proxool.j07:org.hsqldb.jdbc.JDBCDriver:jdbc:hsqldb:mem:test");
System.out.println(conn);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
//通过properties文件获取
//1、直接添加参数
public static void main(String[] args) throws Exception {
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
Properties info = new Properties();
info.setProperty("user", "sa");
info.setProperty("password", "");
String alias = "j07";
String driverClass = "org.hsqldb.jdbc.JDBCDriver";
String driverUrl = "jdbc:hsqldb:mem:test";
String url = "proxool." + alias + ":" + driverClass + ":" + driverUrl;
Connection connection = DriverManager.getConnection(url, info);
System.out.println(connection);
}
//2、写properties文件
jdbc-0.proxool.alias=J07
jdbc-0.proxool.driver-url=jdbc:hsqldb:mem:test
jdbc-0.proxool.driver-class=org.hsqldb.jdbc.JDBCDriver
jdbc-0.user=SA
jdbc-0.password=
jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE
public static void main(String[] args) {
try {
PropertyConfigurator.configure("src/proxool.properties");
//切记j07配置时需要大写
Connection conn=DriverManager.getConnection("proxool.J07");
System.out.println(conn);
} catch (Exception e) {
e.printStackTrace();
}
}
//读取xml
<proxool>
<alias>J07</alias>
<driver-url>jdbc:hsqldb:mem:test</driver-url>
<driver-class>org.hsqldb.jdbc.JDBCDriver</driver-class>
<driver-properties>
<property name="user" value="http://www.mamicode.com/sa"></property>
<property name="password" value=""></property>
</driver-properties>
</proxool>
public static void main(String[] args) {
try {
JAXPConfigurator.configure("src/proxool.xml",false);
//切记j07配置时需要大写
Connection conn=DriverManager.getConnection("proxool.J07");
System.out.println(conn);
} catch (Exception e) {
e.printStackTrace();
}
}
//web中获取
//1、读取properties文件
jdbc-0.proxool.alias=J07
jdbc-0.proxool.driver-url=jdbc:hsqldb:mem:test
jdbc-0.proxool.driver-class=org.hsqldb.jdbc.JDBCDriver
jdbc-0.user=SA
jdbc-0.password=
jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE
web.xml
<servlet>
<servlet-name>ServletConfigurator</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
<init-param>
<param-name>propertyFile</param-name>
<param-value>proxool.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>admin</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>admin</servlet-name>
<url-pattern>/admin</url-pattern>
</servlet-mapping>
获取
Connection conn=DriverManager.getConnection("proxool.J07");
xml获取
<proxool>
<alias>J07</alias>
<driver-url>jdbc:hsqldb:mem:test</driver-url>
<driver-class>org.hsqldb.jdbc.JDBCDriver</driver-class>
<driver-properties>
<property name="user" value="http://www.mamicode.com/sa"></property>
<property name="password" value=""></property>
</driver-properties>
</proxool>
web.xml
<servlet>
<servlet-name>ServletConfigurator</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
<init-param>
<param-name>xmlFile</param-name>
<param-value>proxool.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>admin</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>admin</servlet-name>
<url-pattern>/admin</url-pattern>
</servlet-mapping>
获取
Connection conn=DriverManager.getConnection("proxool.J07");
proxool的配置