Tomcat5.0 Configure the connection pool (JTDS driver) with SQLServer2000

xiaoxiao2021-03-06  77

Software: (1) Tomcat5.0

http://apache.linux process.net/dist/j...mcat-5.0.25.exe

(2) jtds.jar

http://jtds.sourceforge.net/

(3) JDK1.4 (4) SQLServer2000 (Windows2003 system requires SP3 patch) Set environment variables: (1) Catalina_home Tomcat installation path, such as: E: /TOMCAT5.0 (2) Cataalina_base Tomcat installation path, such as: E: E : / Tomcat5.0 (3) Java_Home JDK Installation Path, such as: E: / Program Files / J2SDK1.4.2 (4) Path% Java_Home% / BIN (5) Class_Path.;% Java_Home% / lib / dt.jar;% Java_Home% / lib / Tools.jar;% catalina_home% / common / lib / servlet-api.jar (front. And; can not be less) to put jtds.jar in the correct directory can only be placed at% CATALINA_HOME% / Common / Modify the server.xml file in the lib / directory in:;% CATALINA_HOME% / conf / server.xml in and

Between, the modified content is:

"E: / tiannet" debug = "5" reloadable = "true" crosscontext = "true"

>

"org.apache.catalina.logger.filelogger" Directory = "logs" prefix = "localhost_log." SUFFIX =

".txt" TimeStamp = "True"

/>

"JDBC / ConnectDB" Auth =

"Container" type = "javax.sql.datasource"

/>

>

> Factory

> Org.apache.commons.dbcp.basicdataasourcefactory

>

>

> removeabandoned

> True

>

> removeabandonedTimeout

> 60

>

>

> logabandoned

> false

>

>

> maxactive

> 100

>

>

> maxidle

> 30

>

>

> maxwait

> 10000

>

>

> Username

> sa

>

>

> Password

> 123

>

>

> driverclassname

> Net.SourceForge.jtds.jdbc.driver

>

>

> URL

> JDBC: JTDS: SQLServer:

//127.0.0.1:1433/tiannet; character cNET ;Charset=GB2312

>

> Parameter Description 1) Path Specifies the path, which is to access the web, here http: // localhost: 8080 / Tiannet

2) The path of the DOCBase virtual directory, absolute path. If the virtual directory sets the% catalina_home% / webapps directory (such as tiannet), you can write the subdirectory name (such as tiannet). 3) RELOADER is recompiled when the web is updated. 4) The maximum number of database connections for the MaxActive connection pool. Set to 0 means unlimited. 5) The maximum idle time for the MaxIdle database connection. More than this idle time, the database connection will be marked as unavailable and then released. Set to 0 means unlimited. 6) MaxWait builds a maximum connection wait time. If you exceed this time will receive an exception. Set to -1 means unlimited. 7) Removeabandoned recycles abandoned (generally forgotting the release) database connection to the connection pool. 8) RemoveabandONEDTIMEOUT Database Connections After the connection is not considered to be abandoned and the connection pool is retracted. 9) logabandoned will be recorded in the logged database. 10) DriverclassName JDBC driver. 11) Username: Username 12) Password: Password: Connect Database 13) URL Format Database Connection String (Tiannet here), format: JDBC: JTDS: : // : // [: ] [/ = [; ...]] More URL instructions for URL, please refer to: http://jtds.sourceforge.net/faq.html Modify the above content and then restart Tomcat, one XML file will be taken in% CATALINA_HOME% / conf / catalina / localhost / directory, here: tiannet.xml. Now the virtual directory will take effect.

Modify the /Web-inf/web.xml file Create a web-inflicate under the root of the virtual directory (here: E: / Tiannet), create a web.xml file in the web-inflicity, the basic content is: < XML Version = "1.0" encoding = "ISO-8859-1"> TianNet Web ConnectDB Test DB Connection JDBC / ConnectDB javax.sql.datasource Container < / res-auth> index.jsp Note JDBC / ConnectDB The Name property in the JDBC / ConnectDB and Server.xml files in the server.xml file is the same.

Test connection pool code <% @ Page ContentType = "text / html; charset = GB2312"%> <% @ page import = "java.sql. *"%> <% @ Page import = "javax.sql. *" %> <% @ page import = "javax.naming. *"%> <% datasource ds = null; connection conn = null; resultset = null; statement stmt = null; initialcontext ctx = null; String m_striver = "net.sourceforge.jtds.jdbc.driver", // Drive string m_strConURL = "jdbc: jtds: sqlserver"; // Connect string try {ctx = new initialcontext (); ds = (datasource) CTX .lookup ("Java: Comp / Env / JDBC / ConnectDB"); // Note that the name of ConnectDB and the same consequent conn = ds.getConnection (); stmt = conn.createstatement (); string strsql = "select * from test" // Test is a table RS = stmt.executeQuery (strsql) in the database; while (rs.next ()) {outputln (rs.getstring (1) "); out.println (Rs.getstring (2) "" "); } Catch (exception ex) {out.println (ex.getMessage ());} finally {r.close (); stmt.close (); conn.close (); ctx.close ();}%>

转载请注明原文地址:https://www.9cbs.com/read-108797.html

New Post(0)