Where The Streets Have No Name

Using MySQL database with OC4J 본문

Developement/Java

Using MySQL database with OC4J

highheat 2006. 8. 18. 15:31
http://radio.weblogs.com/0135826/2004/03/29.html

Configure OC4J

1. Install JDBC Diver

You have to copy the JDBC driver library i.e. mysql-connector-java-3.0.11-stable-bin.jar to %OC4J_HOME%/j2ee/home/applib directory.

2. Create DataSource

Create the datasource entry for connecting to the MySQL database in the %OC4J_HOME%/j2ee/home/config/data-sources.xml as follows:

<data-source

class="

com.mysql.jdbc.jdbc2.optional.MysqlDataSource"

name="mysqlDS"

location="jdbc/mysqlCoreDS"

xa-location="jdbc/xa/mysqlXADS"

ejb-location="jdbc/mysqlDS"

connection-driver="com.mysql.jdbc.Driver"

username="root"

password="welcome"

url="jdbc:mysql://

144.25.134.24/Test"

inactivity-timeout="30"

/>

3. Test DataSource

You have to restart OC4J before you can use the DataSource you created in the previous step. Here is a sample JSP that you can use to test the DataSource that you created in the previous step.

<%@ page import="java.sql.*, javax.naming.*, javax.sql.*" %>

<% try { InitialContext ctx = new InitialContext();

DataSource ds = (DataSource) ctx.lookup("jdbc/mysqlDS");

Connection con = ds.getConnection(); Statement statement = con.createStatement();

ResultSet rset = statement.executeQuery("select * from emp"); %>

<h1> Test OC4J with MySQL DB </h1>

<table border=1 align=center>

 <% while (rset.next()) { %>

 <TR><TD>

<%= rset.getInt(1) %>

 <TD>

<%= rset.getString(2) %>

<% } statement.close();

con.close(); }

catch(Exception e)

{ out.print(e.getMessage()); }

%>

한글처리관련 수정사항

<data-source
       class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
       name="mysqlDS"
       location="jdbc/mysqlCoreDS"
       xa-location="jdbc/xa/mysqlXADS"
       ejb-location="jdbc/mysqlDS"
       connection-driver="org.git.mm.mysql.Driver"
       username="root"
       password=""
       url="jdbc:mysql://localhost:5000/test?characterEncoding=euckr"
       inactivity-timeout="30"
   />