Overview

General

Configuration

Servers

Integrations

Community

Feeds


Site
News
   



MySQL [ edit ]

How do I setup OpenEJB to use MySQL?

Here are my config files for getting the CMP entity example to work. Note that the mm driver is no longer available from sourceforge and must now be directly downloaded from www.mysql.com and that the driver name has changed. The config files below use the new driver package/name and work with MySQL 4.0.3 beta on Windows2000.

The SQL statement used to create the employee table was:

create table employee (
   id integer primary key auto_increment,
   first_name varchar(15), 
   last_name varchar(15),
   email varchar(30)
);
openejb.conf
<?xml version="1.0"?>

<openejb>
  <Container id="Default CMP Container" ctype="CMP_ENTITY">
    Global_TX_Database c:/java/j2ee/openejb/hello_world_cmp/conf/hello.cmp_global_database.xml
    Local_TX_Database  c:/java/j2ee/openejb/hello_world_cmp/conf/hello.cmp_local_database.xml
  </Container>
  <Deployments jar="c:/java/j2ee/openejb/hello_world_cmp/employee.jar"/>
  <Connector id="Default JDBC Database">
    JdbcDriver  com.mysql.jdbc.Driver
    JdbcUrl     jdbc:mysql://localhost/openejb_cmp_example
    UserName    cso4309
    Password 
  </Connector>
  <SecurityService id="Default Security Service"/>
  <TransactionService id="Default Transaction Manager"/> </openejb>
hello.cmp_global_database.xml
<?xml version="1.0"?>

<database name="Global_TX_Database" engine="mysql">
    <jndi name="java:comp/env/jdbc/openejb_cmp_example" />
    <mapping href="c:/java/j2ee/openejb/hello_world_cmp/conf/hello.cmp_or_mapping.xml" /> 
</database>
hello.cmp_local_database.xml
<?xml version="1.0"?>

<database name="Local_TX_Database" engine="mysql" >

    <driver class-name="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost/openejb_cmp_example">
      <param name="user"     value="cso4309" />
      <param name="password" value="" />
    </driver>

    <mapping href="c:/java/j2ee/openejb/hello_world_cmp/conf/hello.cmp_or_mapping.xml" /> 
</database>
hello.cmp_or_mapping.xml
<?xml version="1.0"?>

<mapping>
  <class name="org.acme.employee.EmployeeBean" identity="id" key-generator="IDENTITY">
    <map-to table="employee"/>
    <field name="id" type="integer" direct="true">
      <sql name="id" type="integer"/>
    </field>
    <field name="firstname" type="string" direct="true">
      <sql name="first_name" type="varchar" dirty="check"/>
    </field>
    <field name="lastname" type="string" direct="true">
      <sql name="last_name" type="varchar" dirty="check"/>
    </field>
    <field name="email" type="string" direct="true">
      <sql name="email" type="varchar" dirty="check"/>
    </field>
  </class>
</mapping>

Where can i get the MySQL JDBC driver?

The mm driver is no longer available from sourceforge, the new driver is called Connector/J and must now be directly downloaded from www.mysql.com at http://www.mysql.com/downloads/api-jdbc-stable.html

         
     
     
     
 


Apache OpenEJB is an project of The Apache Software Foundation (ASF)
 
Powered by Atlassian Confluence.