Jboss3.0 + atat4.06 configure MySQL database _ MySQL

Source: Internet
Author: User
Jboss3.0 + tomcat4.06 configure MySQL database Tomcat

1. change the Tomcat startup Port: modify the serverdefaultdeploytomcat4-service.xml file under the JBoss installation directory. Find Connector className = "org. apache. catalina. connector. http. HttpConnector" and change the port to the desired port number.

2. after JBoss is started, access the Tomcat port (8080 by default). The solution is 500 error (that is, how to deploy your web application, servlet and so on are packaged into * according to J2EE specifications *. war: add the generated war file to serverdefaultdeploy. JBoss will automatically deploy the file. Then, enter the corresponding path to access the file.

3. establish a connection pool (with MySql ):

(1) modify the mysql-service.xml file in docsexamplesjca under the JBoss installation directory, find config-property name = "ConnectionURL" and change the content to the appropriate network service name (such as mydql connection: jdbc: mysql: // 127.0.0.1: 3306/test ), find config-property name = "UserName" and config-property name = "Password" and change it to the user name and Password of your database. Save the file and copy it to the serverdefaultdeploy directory.

(2) copy the JDBC driver (mm. mysql-2.0.14-bin.jar) provided by mysql to the serverdefalib Lib directory.

(3) restart the server and establish the connection pool.

(4) test:

<% @ Page contentType = "text/html;" import = "javax. ejb. *, javax. naming. *, java. rmi. *, javax. rmi. *, java. util. *, java. SQL. *, javax. SQL. * "%>

<%

Context ctx = null;

DataSource ds = null;

Connection conn = null;

PreparedStatement stmt = null;

ResultSet rs = null;

Try

{

Ctx = new InitialContext ();

Ds = (DataSource) ctx. lookup ("java:/MySqlDS ");

Conn = ds. getConnection ();

String str = "select id from test. test ";

Stmt = conn. prepareStatement (str );

Rs = stmt.exe cuteQuery ();

If (rs. wasNull ())

{

Out. println ("no data ");

}

While (rs. next ())

{

Out. println (rs. getInt ("id "));

}

Rs. close ();

Stmt. close ();

Conn. close ();

}

Catch (Exception e)

{

System. out. println (e );

}

%>

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.