Deploy SQLJ applications that use bean-managed persistence


 

+

Search Tips   |   Advanced Search

To deploy SQLJ applications that do not use container-managed persistence...

  1. Translate the SQLJ application to configure for the appserver environment
  2. Customize the SQLJ profiles

New feature: The appserver includes these new features for SQLJ support for applications that use bean-managed persistence:

 

Procedure

  1. Create a backup copy of the .java file.

    For example if the file is called MyServlet.java, copy MyServlet.java to MyServlet.java.bkup.

  2. Rename the .java file to a file name with a .sqlj extension.

    For example, rename MyServlet.java to MyServlet.sqlj

  3. Edit the .sqlj file to convert the JDBC syntax to SQLJ syntax.

    When using SQLJ, if we want connection management for the appserver to function properly, specify correct connection contexts.

    For example, convert the following JDBC operation:

     Connection con = dataSource.getConnection();
      Statement stmt = con.createStatement();
      stmt.execute("INSERT INTO users VALUES (1, 'user1')");
      con.commit();
    

    ...to the following SQLJ...

    
    // At the top of the file and just below the import statements, define Connection_Context 
    #sql context Connection_context;
     
    . 
    .  Connection con = dataSource.getConnection(); 
    . 
    .  Connection_context ctx1 = new Connection_context(con); 
    . 
    . 
    #sql [ctx1] {INSERT INTO users VALUES (1, 'user1')}; 
    .  
    .   con.commit(); ctx1.close();
    

    When you run the SQLJ translator, the .java file that the tool creates will have the same name as the old .java file, providing you with a seamless transition to the SQLJ technology.

  4. From the DB2 installation, copy the sqlj.zip file to a directory on the workstation.

    Modify the Java build path of the JAR file project to include the sqlj.zip file.

  5. Use RAD or the DB2 SQLJ translator to automatically translate SQLJ.

    • Use RAD:

      1. In the Project Navigator, right-click the JAR project, and select Add SQLJ Support....

      2. Select the boxes for the applications for which you want SQLJ support.

      3. In the SQLJ JAR file field, type the fully qualified path to the sqlj.zip file that you previously copied to the workstation.

      4. Click Finish.

      5. Export the EAR file.

    • Use the DB2 SQLJ translator.

      This tool creates a .java version of the .sqlj file and a serialized profile, with a .ser extension, used later in processing.

  6. Package the JAR file for the enterprise application.

  7. Install the application onto the appserver, or customize the profiles with the db2sqljcustomize tool.

To customize the profiles with the appserver....

Avoid trouble: Do not select Deploy enterprise beans during the application installation process in the admin console. If we redeploy the enterprise beans from the admin console, you will lose the customization changes that we have made.

The appserver provides enhanced support for SQLJ applications. Install the SQLJ application in the appserver , and we can customize and bind SQLJ profiles through the admin console or scripting:

 

Related tasks

Data access beans
Customize profiles for SQLJ applications
Customize SQLJ profiles with the db2sqljcustomize tool
Deploy SQLJ applications that use CMP
Deploy SQLJ applications that use CMP with the ejbdeploy tool
RAD: Developing SQLJ applications

 

Related


Application management
Exceptions pertaining to data access