Saturday, April 24, 2010

Connecting MySQL Database with Jdeveloper 11g


Hi all,

In order to create ADF application on based on MySQL database you need some little different steps to work with it. Possibly you will hit by some bugs and for example you cannot create EOs and VOs by using normal Business Component Wizard you have to create Entity object, View Objects, Application Module manually (as i experienced). To connect mysql from any J2EE application you need to work with special driver called Connect/J.

Enough talking lets get into the steps

Pre-requisites:
- Download MySQL from mysql website
- Install MySQL (as simple any blind man can do the installation)
- Make sure MySQL database is up and running (Windows services MySQL 5.1)
 Note: I have one table called Mytable in mysql database named "mysql"



- Download Connect/J and extract it on your computer
- Copy the mysql-connector-java-5.1.12-bin.jar file and paste into
C:\oracle\Middleware\user_projects\domains\\lib
(it is required you to create a custom domain in weblogic server to deploy your applications) 
- Rename the Jar file to mysqljdbc.jar for ease of administration.


Creating connection in Application:

- Create New ADF fusion based on Fusion application template.
- Create connection named mysqlconn
- Enter settings as shown in the slide (its the defaults of mysql)
- Click the Browse button with the Library
- Create New on the Left side Add an Entry called MYSQL in User Section
- Select Classpath and Choose Add Entry and select the path where you have putted the mysqljdbc.jar file
- Click OK

- Test the Connection

Creating EOs, VOs and AM:
- I am not going into detail (if you are regular blog visitor you know the rest) of these steps just for help you can follow the important slides.
- Right click on Model Page and Choose New Entity Object


 - Right click MyTableEO and choose New Default View Object.

 - Create Application Module

- Add an Instance of MyTableVO

- Right Click Application Module Choose Run
- Business Component Browser will open which means our Model project is Working OK


-Create a Basic JSF page and Drag and Drop ADF Read-only Table on the page


Note: You might not able to run it from integrated weblogic server because of our mysqljdbc.jar is not in classpath of the integrated weblogic server 

Next Step: Deploying MySQL based ADF application to Weblogic Server



Cheers,
Baig

9 comments:

  1. Hi,

    Two points be carefull with mysql and adf bc, you can't passivate or activate am sessions because mysql cant work with the ps_txn table

    and when you deploy to a wls then you better replace the internal connector/j library , Oracle deliver wls with a old version 5.0.5

    thanks

    ReplyDelete
  2. Thanks edwin for your comments

    ReplyDelete
  3. Thank you for your blog.

    But have you ever faced the issue described in http://forums.oracle.com/forums/message.jspa?messageID=9783961 ?

    Please reply in forum.

    ReplyDelete
  4. Nice one yaar.. Tanx a lot.. i could'nt find better than this..

    Keep blogging.. i am very new to ADF ( just 3 days)

    ReplyDelete
  5. Very Lovely article.

    I am however having issues.


    I am using JDeveloper 11g R2 and MySQL running on MAC OSX 10.8.1.

    I can connect to the database from JDeveloper and i can create EOs and Associations but when i bind an OutputTextFormatted to one of the Data controls and run the application, I get the following error

    Messages for this page are listed below.

    com/mysql/jdbc/MySQLConnection

    com.mysql.jdbc.MySQLConnection

    with the below stack trace (truncated)

    <_checkTimestamp> Apache Trinidad is running with time-stamp checking enabled. This should not be used in a production environment. See the org.apache.myfaces.trinidad.CHECK_FILE_MODIFICATION property in WEB-INF/web.xml
    ADF: Adding the following JSF error message: com/mysql/jdbc/MySQLConnection
    java.lang.NoClassDefFoundError: com/mysql/jdbc/MySQLConnection
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)


    I changed the Connection type for the AppModule from JDBC DataSource to JDBC URL and then i get the following error

    Application module is not connected to a database.

    with the below stack trace (Truncated)

    ADF: Adding the following JSF error message: Application module is not connected to a database.
    oracle.jbo.NotConnectedException: JBO-25200: Application module is not connected to a database.
    at oracle.jbo.server.DBTransactionImpl.checkConnected(DBTransactionImpl.java:6810)
    at oracle.jbo.server.DBTransactionImpl2.createPreparedStatement(DBTransactionImpl2.java:398)
    at oracle.jbo.server.DBTransactionImpl.createReUsePreparedStatement(DBTransactionImpl.java:4981)
    at oracle.jbo.server.ViewObjectImpl.getPreparedStatement(ViewObjectImpl.java:13391)
    at oracle.jbo.server.ViewObjectImpl.getPreparedStatement(ViewObjectImpl.java:13366)
    at oracle.jbo.server.QueryCollection.buildResultSet(QueryCollection.java:1123)
    at oracle.jbo.server.QueryCollection.executeQuery(QueryCollection.java:913)
    at oracle.jbo.server.ViewObjectImpl.executeQueryForCollection(ViewObjectImpl.java:7282)
    at oracle.jbo.server.ViewRowSetImpl.execute(ViewRowSetImpl.java:1227)


    Any Help will be greatly appreciated.

    Best Regards

    Paul

    ReplyDelete
    Replies
    1. Hi,

      Looks like there are some issues with configuration. Please double check the steps above. Use JDBC datasource and make sure you have created the datasource in weblogic server and your jdbc driver path exists in CLASSPATH

      the error CHECK_FILE_MODIFICATION is not related you can turn off this by modifying web.xml in the application.

      ZB

      Delete
  6. Not working on linux http://stackoverflow.com/questions/14941065/jdeveloper-and-mysql-interconnection

    ReplyDelete
    Replies
    1. Make sure your CLASSPATH is set to drivers location.

      Zeeshan

      Delete
  7. Hello Zeeshan,
    I've done what is said in this post but when I run the application on glassfish or in model tester - just querying one table - I get the following exception:

    (oracle.jbo.jbotester.ErrorHandler$ExceptionWrapper) JBO-29000: Unexpected exception caught: java.lang.AbstractMethodError, msg=com.mysql.jdbc.ResultSet.isClosed()Z
    ----- Level 1: Detail 0 -----
    (java.lang.AbstractMethodError) com.mysql.jdbc.ResultSet.isClosed()Z

    Could you suggest a solution?

    ReplyDelete