C.3. SQLJ in JavaServer Pages

JavaServer Page s (JSP) are similar to HTML pages except that they contain Java statements in addition to the HTML tags. This section shows a simple JSP, named JSPExample.sqljsp, that contains SQLJ statements, and then describes how to deploy that JSP to iAS. For an introduction to JavaServer Pages, I recommend the book JavaServer Pages by Hans Bergsten (O'Reilly).

A JSP file normally has the extension .jsp. However, a JSP that contains SQLJ statements must have the extension .sqljsp. This extension tells iAS that before running the JSP, it must first use the SQLJ utility to translate any SQLJ statements that may be in the file. The example program, JSPExample.sqljsp (Example C-3), retrieves and displays the same customer details as the other examples in this appendix.

Example C-3. JSPExample.sqljsp
<!-- JSPExample.sqljsp illustrates how to include SQLJ statements in JavaServer Pages. --> <!-- Import the SQLJ classes --> <%@ page import="java.sql.*" %> <%@ page import="sqlj.runtime.ref.DefaultContext,oracle.sqlj.runtime.Oracle" %> <html> <head> <title>Customers</title> </head> <body> <%! // declare an iterator class #sql private static iterator CustIteratorClass( int id, String first_name, String last_name, java.sql.Date dob, String phone ); %> <% try { DefaultContext conn_context = Oracle.connect( "jdbc:oracle:thin:@localhost:1521:orcl", "fundamental_user", "fundamental_password" ); CustIteratorClass cust_iterator; #sql [conn_context] cust_iterator ...

Get Java Programming with Oracle SQLJ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.