Tomcat 6.0.20 data source configuration

Source: Internet
Author: User

From: http://9771104.blog.163.com/blog/static/1944662200991803817362/

 

MyTomcat 6.0.20Installation path:D: \ Tomcat 6.0

1,Configuration Conf \ context. xmlFile

<Resource Name = "JDBC/mysql_pool" auth = "Container" type = "javax. SQL. datasource"

Maxactive = "100" maxidle = "30" maxwait = "10000"

Username = "root" Password = "sunjie" driverclassname = "org. gjt. Mm. MySQL. Driver"

Url = "JDBC: mysql: // localhost: 3306/testweb"/>

Note: (Total score4Column translation)

(1),JNDIConnection username, author, Type

(2), Connection size and wait time

(3), The username, password, and driver used to connect to the databaseProgram

(4), The connection address is: TestwebDatabase

InConf \ context. xmlFile</Context>Previously, add the above content

 

 

2,Configuration Conf \ WEB. xmlFile

<Resource-ref>

<Description> dB connection </description>

<Res-ref-Name> JDBC/mysql_pool </RES-ref-Name>

<Res-type> javax. SQL. datasource </RES-type>

<Res-auth> container </RES-auth>

</Resource-ref>

Note: (Total score3Column translation)

(1),JNDIConnection usernameAndContext. xmlInNameMatch

(2),JNDIConnection TypeAndContext. xmlInTypeMatch

(3),JNDIConnected authorAndContext. xmlInAuthMatch

DescriptionWithout any explanation, you can modify the content on your own, or use your default.

InConf \ context. xmlFile</Web-app>Previously, add the above content

 

 

3,Test successful (Save:Test. jsp)

<% @ Page contenttype = "text/html; charset = gb2312" %>

<% @ Page impORT = "Java. SQL. *" %>

<% @ Page impORT = "javax. SQL. *" %>

<% @ Page impORT = "javax. Naming. *" %>

<%!

Final string jndiname = "Java: COMP/ENV/jdbc/mysql_pool ";

%>

<%

Connection conn = NULL;

Try

{

Context CTX = new initialcontext ();//Initialize the namespace search

Datasource DS = (datasource) CTX. Lookup (jndiname );//FindDatasource

Conn = Ds. getconnection ();

}

Catch (exception E)

{

System. Out. println (E );

}

%>

<% = Conn %>//Print whether the connection is successful

Note: 

StartTomcat 6.0.20In the address bar, enter:Http: // localhost: 8080/test. jspIf the following message is displayed, the configuration is successful.Tomcat 6.0.20Data Source

 

JDBC: mysql: // localhost: 3306/testweb, etc,

The prompt is the same as the original configuration.

 

4,If you are not sure, add the followingCode

Note: In<% = Conn %>Add the following query code:AdminTable, which hasID,Name, passThree fields, depending on your situation.

<Table border = 1>

<Tr>

<TD>UserID:</TD>

<TD>User name:</TD>

<TD>Password:</TD>

</Tr>

<%

String SQL = "select * from admin ";

Preparedstatement pstat = conn. preparestatement (SQL );

Resultset rs1_pstat.exe cutequery ();

While (Rs. Next ())

{

Int id = Rs. getint (1 );

String name = Rs. getstring (2 );

String pass = Rs. getstring (3 );

%>

<Tr>

<TD> <% = ID %> </TD>

<TD> <% = Name %> </TD>

<TD> <% = pass %> </TD>

</Tr>

<%

}

%>

</Table>

 

Error (1), Org. Apache. tomcat. DBCP. DBCP. sqlnestedexception: cannot load JDBC Driver Class 'org. gjt. Mm. MySQL. Driver'

 

Solution: Copy the driver connecting to the databaseTomcatOfLibFolder.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.