Tutorials : Murach's Java Servlets and JSP - Creating an SQL-Java Gateway :

The code for the JSP

The code for the JSP starts with a scriptlet that contains Java code that retrieves two attributes from the session object:

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<% 
   String sqlStatement = 
      (String) session.getAttribute("sqlStatement");
   if (sqlStatement == null) 
      sqlStatement = "";
   String message = 
      (String) session.getAttribute("message");
   if (message == null) 
      message = "";
%> 

The first attribute is the string that contains the SQL statement, and the second attribute is the string that contains the result message. If these attributes contain null values, they haven't been set yet so this code sets the sqlStatement and message variables to empty strings.

This JSP also contains an HTML form that contains a text area and a submit button:

<form action="../servlet/murach.sql.SQLGatewayServlet" method="post">
   <b>SQL statement:</b><br>
   <textarea name="sqlStatement" cols=60 rows=8>
      <%= sqlStatement %>
   <textarea><br>
   <br>
   <input type="submit" value="Execute">
<form>

Here, the text area allows the user to enter the SQL statement. This code creates a text area that's approximately 60 characters wide and 8 lines tall. Within this area, the sqlStatement variable is displayed, which is empty the first time this JSP is run. Then, when the user clicks the submit button, this JSP calls the SQLGatewayServlet that's described later in this article.

The table near the end of the JSP displays the message string that contains the result of the SQL statement:

SQL result:
<table cellpadding="5" border="1"> <%= message %> <table>

Since this message contains the rows and columns for an HTML table, it's coded within the Table tags.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.