When mounting an installation of MySQL master-slave which will be explained another day, I started to configure the corresponding datasource in Glassfish 3 Application Server and I will explain you how to configure this:

1. Download the MySQL JDBC driver from http://dev.mysql.com/downloads/connector/j/3.1.html

2. Extract its contents

3. Copy mysql-connector-java-xxx-bin.jar to the lib folder of your Glassfish installation directory, for example GLASS_FISH_INSTALL_DIR lib.

3. Start GlassFish Application server with the command ‘start-domain domain1 asadmin.bat’ GLASS_FISH_INSTALL_DIR located in the bin directory.

4. Log into the admin console of GlassFish. The default url is http://localhost:4848/login.jsf.

5. From the “Common Task” expand the menu “Resources” menu by clicking on Resources menu.

6. Expand the menu “JDBC” under “Resources”.

7. Select “Connection Pools” menu under the “JDBC.”

8. Select “New”.

9. Specify a name for your “JDBC Connection pool”, select javax.sql.ConnectionPoolDataSource as “Resource Type” and MySQL “Database vendor.”

10.Select “Next”

11.then must complete at least the following information
a. DatabaseName
b. password
c. URL (The syntax is jdbc: mysql :/ / localhost: 3306/test. “Test” is the database name.)
d. Url ((The syntax is jdbc: mysql :/ / localhost: 3306/test. “Test” is the database name.)
e. ServerName
f. User

12. After clicking “Finish” will return to the “Connection Pools”.

13. Select the Connection Pool created earlier.

14. Select Ping. if everything is properly set up the ping will succeed.

15.Ahora select “JDBC resorces” in the “JDBC.”

16. Select “New”

17.Indica a JNDI name for your data source. Select the pool created earlier .

18. Click on OK. Now you can use this data source in the application code using the following Java code

Context ctx = new InitialContext ();
DataSource ds = (DataSource) ctx.lookup (“jdbc / mysqltest”);
Ds.getConnection Connection con = ();
For other database engines would be similar but using the correct driver in each case and changing the “Database Vendor” in the connection pool

Anuncios