Jboss4.0 configure Mysql Data Source

Source: Internet
Author: User

1. To use MySQL in jboss4, first put the JDBC driver of MySQL into classpath.
Similarly, copy it to the/Server/default/lib directory,
(MySQL-connector-Java-is required- 3.0.16 -The ga.zip package extracts the jar files)

II, Then copy the/docs/examples/JCA/mysql-ds.xml to the/Server/default/deploy directory. Modify the mysql-ds.xml file, set it to com. MySQL. JDBC. Driver, and then set it to JDBC: mysql: //, where the Database Host Name is the database name.
Example: <CES>
<Local-TX-datasource>
<JNDI-Name> mysqlds </JNDI-Name>
<Connection-URL> JDBC: mysql: // localhost: 3306/wwx </connection-URL> // wwx
<Driver-class> com. MySQL. JDBC. Driver </driver-class>
<User-Name> root </user-Name>
<Password> root </password>
</Local-TX-datasource>
</Datasources>

3. ,Then you need to set the and elements of the standardjaws. XML (or Jaws. xml Note:/Server/default/conf directory) file:
<Jaws>
<Datasource> JAVA:/mysqlds </datasource>
<Type-mapping> mysql </type-mapping>
.......
</Jaws>


Thu, You also need to set the and element of the standardjbosscmp-jdbc.xml (or jbosscmp-jdbc.xml file note:/Server/default/conf directory) to the following:
<Jbosscmp-jdbc>
<Defaults>
<Datasource> JAVA:/mysqlds </datasource>
<Datasource-mapping> mysql </datasource-mapping>
</Defaults> </jbosscmp-jdbc>

V., And finally modify the login-config.xml (/Server/default/conf directory) file to use MySQL:
<Application-Policy Name = "mysqldbrealm">
<Authentication>
<Login-module code = "org. JBoss. Resource. Security. configuredidentityloginmodule" flag = "required">
<Module-option name = "principal"> wwx </Module-option>
<Module-option name = "username"> root </Module-option>
<Module-option name = "password"> root </Module-option>
<Module-option name = "managedconnectionfactoryname"> JBoss. JCA: service = localtxcm, name = mysqlds
</Module-option>
</Login-module>
</Authentication>
</Application-Policy>

Sat., Modified the mysql-ds.xml, standardjaws. XML, standardjbosscmp-jdbc.xml, and login-config.xml files can use MySQL on JBoss.

VII., Debugging code
Debugging is successfully called in servlet Init ().
Context CTX = new initialcontext (); // get the initialization Context
Object OBJ = CTX. Lookup ("Java:/mysqlds"); // query the connection pool
Datasource DS = (datasource) OBJ; // convert to datasource
Connection connect = Ds. getconnection (); // obtain a connection from the connection pool.
// System. Out. println ("Success connect MySQL connection
// Pool! ");
Statement stmt = connect. createstatement ();
Resultset rs = stmt.exe cutequery ("select * From userinfor ");
While (Rs. Next ()){
Temp = Rs. getstring ("name ");
}
} Catch (exception e ){
// System. Out. Print ("Get data error! ");
E. printstacktrace ();
}

 

 

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.