WAS v8.5 > Deploy applications > Deploy data access resources > Deploy SQLJ applicationsDeploy SQLJ applications that use bean-managed persistence, servlets, or sessions beans
We can embed SQLJ statements in the applications to maximize the efficiency of transactions with the databases. Before the applications can take advantage of SQLJ, deploy the application and customize the created SQLJ profiles. We can use Rational Application Developer or the DB2 SQLJ translator to translate the application before deploying it on the application server.
Create an SQLJ application using Rational Application Developer or another development tool.
To deploy SQLJ applications that do not use container-managed persistence, translate the SQLJ application first to configure it for the application server environment. After translation, customize the SQLJ profiles in the application server, with scripting, or with the db2sqljcustomizer tool.
SQLJ support for applications that use bean-managed persistence include these features:
- Customizing and binding SQLJ profiles with the dmgr console or scripting.
- Customizing and binding SQLJ applications again without reinstalling the application.
- Optional: Create a backup copy of your .java file. For example if your file is called MyServlet.java, copy MyServlet.java to MyServlet.java.bkup.
- Optional: Rename your .java file to a file name with an .sqlj extension. For example, if the application is a servlet named MyServlet.java, rename MyServlet.java to MyServlet.sqlj
- Optional: Edit the SQLJ file to convert the JDBC syntax to SQLJ syntax. When using SQLJ, if you want connection management for the application server 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 is created has the same name as your old .java file. This provides you with a seamless transition to the SQLJ technology.
- From your DB2 installation, copy the sqlj.zip file to a directory on your workstation. Modify the Java build path of your enterprise bean JAR file project to include the sqlj.zip file.
- Use Rational Application Developer or the DB2 SQLJ translator to automatically translate SQLJ.
- Use Rational Application Developer:
- In the Project Navigator, right-click your JAR project, and select Add SQLJ Support....
- Select the check boxes for the applications for which you want SQLJ support.
- In the SQLJ JAR file field, type the fully qualified path to the sqlj.zip file that you previously copied to your workstation.
- Click Finish.
- Export the EAR file.
- Use the DB2 SQLJ translator. This tool creates a .java version of the .sqlj file and a serialized profile, with an .ser extension, used later in processing. Refer to the DB2 documentation for more information about the SQLJ translator tool.
- Package your JAR file for the enterprise application.
- Install the application onto the application server, or customize the profiles with the db2sqljcustomize tool.
- Customize the profiles with the application server.
- Package the JAR file for the enterprise beans, servlets, and any .ser files into an enterprise archive.
- Install the application in the application server, and customize SQLJ profiles with the dmgr console or wsadmin.
Do not select Deploy enterprise beans during the application installation process in the dmgr console. If you redeploy the enterprise beans from the dmgr console, you lose the customization changes that we have made. The application server provides enhanced support for SQLJ applications. Install the SQLJ application in the application server, and we can customize and bind SQLJ profiles through the dmgr console or scripting:
- To customize the SQLJ profiles with the dmgr console, read the topic about customizing and binding profiles for SQLJ applications.
- To customize SQLJ profiles with scripting, read the topic about the application management command group for AdminTask.
- To use the db2sqljcustomize tool, read the topic about customizing and binding SQLJ profiles with the db2sqljcustomize tool for more information.
Related concepts:
Data access beans
Related
Customize and binding profiles for SQLJ applications
Customize and binding SQLJ profiles with the db2sqljcustomize tool
Deploy SQLJ applications that use container-managed persistence
Deploy SQLJ applications that use container-managed persistence with the ejbdeploy tool
Rational Application Developer: Developing SQLJ applications
Reference:
Application management command group for AdminTask
Exceptions pertaining to data access