Skip to main content

Java EE 5 samples integarte well with mysql database

Posted by msreddy on March 28, 2008 at 10:02 AM PDT

As part of bundling mysql with GlassFish application server, I set out to test one of the existing samples on mysql which so far used the default Java DB database. It was easy and here are the steps.

  • Install the application server out of the bundle which includes MySQL.
  • Start MySQL DB.
    Refer this install guide for information on how to start MySQL server.
  • login to MySQL data base as root

    grant all privileges on *.* to 'dbuser'@'localhost' identified by 'dbpassword';

    One can be more specific while granting privileges to restrict the scope of access. In addition, the values used for user 'dbuser' and password 'dbpassword' are suggestive, you are free to change them but make sure they are referred appropriately in jdbc connection pool.

  • Start the application server and connect to it through a browser at admin port 4848.

    create jdbc connection pool using the node Resources/JDBC/Connection Pools

    Name: mysqlPool
    Resource Type: javax.sql.DataSource
    Database Vendor: mysql

    click on next and define the following properties

    databaseName: test
    user: dbuser
    password: dbpassword
    Url: jdbc:mysql://localhost:3306/test
    URL: jdbc:mysql://localhost:3306/test

    The default port for MySQL is 3306. If it is different, replace the port 3306 with the correct port number.

  • Crate jdbc resource using the node Resources/JDBC/JDBC Resources
    JNDI Name: jdbc/mysql
    Pool Name: mysqlPool
  • Deploy the attached war file jsf-jpa-war.war whose ./src/conf/persistence.xml uses jdbc/mysql

    For more information on the jsf-jpa-war sample, please refer to
    sample documentation.

    This is a part of the Java EE 5 samples bundle which can be downloaded from https://glassfish-samples.dev.java.net/

  • Verify the working of deployed war by connecting to localhost:8080/jsf-jpa-war
    Related Topics >>