3 Replies Latest reply on Sep 18, 2003 2:55 AM by naveen1975

    configure jboss 4.0 with MySql server

    shehan Newbie

      hi guys,
      Can anybody plsss tell me how to configure jboss 4.0 to MySql.I want to to use MySql as my default database server of jboss 4.0.
      I did it in jboss 3.2, it worked properly, but it didn't work for jboss 4.0. So plss anybody can help me?

        • 1. Re: configure jboss 4.0 with MySql server
          Juha Lindfors Master

          4.0 is a developer's release so you probably should not be using it yet.

          -- Juha

          • 2. Re: configure jboss 4.0 with MySql server
            shehan Newbie

            Anyway, if somebody has done it...plsss tell me how u did that

            • 3. Re: configure jboss 4.0 with MySql server
              naveen1975 Newbie

              I am a new bie to Jboss 4.0, but after spending come time and going thru documentation.. i got it worked.

              Here are the steps:

              1. Create the mysql-ds.xml file with the following config info.

              <?xml version="1.0" encoding="UTF-8"?>

              <local-tx-datasource>
              <jndi-name>MySqlDS</jndi-name>
              <connection-url>jdbc:mysql://localhost/db</connection-url>
              <driver-class>org.gjt.mm.mysql.Driver</driver-class>
              <min-pool-size>5</min-pool-size>
              </local-tx-datasource>



              2. Copy this file into the default/deploy directory of jboss.
              3. Also get the latest version of Mysql JCA Conector from mysql.com. It is named 'mysql-connector-java-3.0.8-stable-bin.jar'.
              4. Copy this file into deploy/lib directory.

              Now you are ready to access the database. Here is the a small snippet to access database in some session bean.

              Get the datasource.
              Note: check the jndi name in the above configuration.

              InitialContext ctx = new InitialContext();

              //Load mysql datasource
              ds = (DataSource) ctx.lookup("java:/MySqlDS");
              System.out.println("Data source initialized.");

              .
              .
              .

              Access the database:
              java.sql.Connection conn = ds.getConnection();

              java.sql.Statement stmt = conn.createStatement();
              String sql = "SELECT name FROM trail";
              java.sql.ResultSet rs = stmt.executeQuery(sql);

              while(rs.next())
              data.addElement(rs.getString(1));

              conn.close();





              I hope that helps.

              Naveen.