Tutorials to .com

Tutorials to .com » Software » Java » DBCP connection pool test (August revision)

DBCP connection pool test (August revision)

Print View , by: iSee ,Total views: 76 ,Word Count: 2169 ,Date: Wed, 26 Aug 2009 Time: 10:10 PM

DBCP connection pool test (August revision)

System:

WIN2000>> APACHE TOMCAT5.0.28 (requirement 5.0 and above)>> SQL SERVER 2000

The system using a SQL SERVER library Northwind. Using the fourth-class driver, driver class into the D: \ testpool \ WEB-INF \ lib in the.

To ensure normal operation of TOMCAT and SQL SERVER.

[1]% TOMCAT_HOME% \ conf \ Catalina \ localhost \ directory to build a testPool.xml file:

<? xml version ='''' 1.0''''encoding ='''' utf-8''''?>

<Context DocBase="D:/testpool" path="/testpool" privileged="true" workDir="work\Catalina\localhost\testpool">

<Resource Type="javax.sql.DataSource" auth="Container" name="jdbc/northwind"/>

<ResourceParams Name="jdbc/northwind">

<parameter>

<name> maxWait </ name>

<value> 5000 </ value>

</ parameter>

<parameter>

<name> maxActive </ name>

<value> 4 </ value>

</ parameter>

<parameter>

<name> password </ name>

<value> jckjdkmcj </ value>

</ parameter>

<parameter>

<name> url </ name>

<value> jdbc: microsoft: sqlserver: / / 10.0.0.168:1433; databaseName = Northwind </ value>

</ parameter>

<parameter>

<name> driverClassName </ name>

<value> com.microsoft.jdbc.sqlserver.SQLServerDriver </ value>

</ parameter>

<parameter>

<name> maxIdle </ name>

<value> 2 </ value>

</ parameter>

<parameter>

<name> username </ name>

<value> sa </ value>

</ parameter>

</ ResourceParams>

</ Context>

[2] D: \ testpool \ WEB-INF \ following the establishment of a web.xml file:

<? xml version = "1.0" encoding = "ISO-8859-1"?>

<web-app xmlns = "http://java.sun.com/xml/ns/j2ee"

xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"

xsi: schemaLocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

version = "2.4">

<! - ConnectionPool ->

<resource-ref>

<res-ref-name> jdbc / northwind </ res-ref-name>

<res-type> javax.sql.DataSource </ res-type>

<res-auth> Container </ res-auth>

</ resource-ref>

</ web-app>

[3] D: \ testpool \ following the establishment of test file index.jsp

<% @ Page contentType = "text / html; charset = GB2312"%>

<% @ Page import = "java.sql .*"%>

<% @ Page import = "javax.sql .*"%>

<% @ Page import = "javax.naming .*"%>

<% @ Page session = "false"%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title> tetst connection pool </ title>

"%

out.println ( "My test started");

DataSource ds = null;

try (

InitialContext ctx = new InitialContext ();

ds = (DataSource) ctx.lookup ( "java: comp / env / jdbc / northwind");

Connection conn = ds.getConnection ();

Statement stmt = conn.createStatement ();

String strSql = "select * from Categories";

ResultSet rs = stmt.executeQuery (strSql);

while (rs.next ()) (

out.println (rs.getString (1));

)

out.println ( "My test is over");

)

catch (Exception ex) (

out.print ( "there is an exception, the information is:" + ex.getMessage ());

ex.printStackTrace ();

)

% "

</ head>

<body>

</ body>

</ html>

[4] added: make configuration roughly similar to a few questions to find out is to consider the WWW principle, to build or change what documents (WHO), where they do (WHERE), what to do (WHAT). Corresponding are:

WHO

WHERE

WHAT

testPool.xml

% TOMCAT_HOME% \ conf \ Catalina \ localhost \

See the first step

web.xml (name fixed)

D: \ testpool \ WEB-INF \ web.xml

See Step

index.jsp

D: \ testpool \ index.jsp

See the third step

[5] If you are using hibernate, except for the above things still need to change the hibernate.cfg.xml file:

<? xml version ='''' 1.0''''encoding ='''' UTF-8''''?>

<! DOCTYPE hibernate-configuration PUBLIC

"- / / Hibernate / Hibernate Configuration DTD 2.0 / / EN"

"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<! - DO NOT EDIT: This is a generated file that is synchronized ->

<! - By MyEclipse Hibernate tool integration. ->

<hibernate-configuration>

<session-factory>

<! - Properties

<property name="connection.username"> sa </ property>

<property name="connection.url">

jdbc: microsoft: sqlserver: / / 10.0.0.168:1433; DataBaseName = cw_scene

</ property>

<property name="dialect">

net.sf.hibernate.dialect.SQLServerDialect

</ property>

<property name="connection.password"> jckjdkmcj </ property>

<property name="connection.driver_class">

com.microsoft.jdbc.sqlserver.SQLServerDriver

</ property>

<property name="hibernate.jdbc.fetch_size"> 50 </ property>

<property name="hibernate.jdbc.batch_size"> 25 </ property>

- "

<! - Properties ->

<property name="connection.datasource">

java: comp / env / jdbc / testpool

</ property>

<property name="dialect">

net.sf.hibernate.dialect.SQLServerDialect

</ property>

<property name="hibernate.connection.provider_class">

net.sf.hibernate.connection.DatasourceConnectionProvider

</ property>

<property name="hibernate.jdbc.fetch_size"> 50 </ property>

<property name="hibernate.jdbc.batch_size"> 25 </ property>

<! - Mapping files ->

<mapping resource="com/scenechina/table/Imgpos.hbm.xml" />

</ session-factory>

</ hibernate-configuration>



Java Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.