Basic JSP Sample : Database Access - JDBC

Previous Contents Next

Contents

Purpose

Connect to the database and perform database operations using JDBC.

Remarks

This sample uses Java Database Connectivity (JDBC) within a JSP to connect to the database and perform a dynamic query against an Oracle database. A JavaBean, implemented in JdbcQueryBean.java, provides the application logic. The JSPs use HTML to define the presentation format, invoking the JavaBean to generate dynamic data.

Code from CountriesJdbc.jsp

<%-- Declare the java bean for the countries to be queried --%>
<jsp:useBean id="JdbcQueryBean" class="JdbcQueryBean" scope="page" />
<%-- Bean property searchCondition is not set to query countries --%>
<jsp:setProperty name="JdbcQueryBean" property="searchCondition" />
<HTML>
<HEAD>
<TITLE>OC4J JSP Sample - Database Access Using Java Bean </TITLE>
</HEAD>
<BODY BGCOLOR="white">
<CENTER>
<%= JdbcQueryBean.getResult() %>
<BR>
</CENTER>
</BODY>
</HTML>

 

Code from CitiesJdbc.jsp

<% // Store the input parameter in a local variable
String searchCondition=request.getParameter("searchCondition");
if (searchCondition!=null) {
session.putValue("searchCondition",searchCondition);
} else {
searchCondition=(String)session.getValue("searchCondition");
}
%>

<%-- Declare the java bean for the cities to be queried --%>
<jsp:useBean id="JdbcQueryBean" class="JdbcQueryBean" scope="page" />
<%-- Set the bean property searchCondition equal to the input parameter. --%>
<jsp:setProperty name="JdbcQueryBean" property="searchCondition"
value="<%= searchCondition %>" />

<HTML>
<HEAD>
<TITLE>OC4J JSP Sample - Database Access Using Java Bean</TITLE>
</HEAD>
<BODY BGCOLOR="white">
<SCRIPT language="javascript">
function back() {
}
</SCRIPT>
<FORM>
<CENTER>
<%= JdbcQueryBean.getResult() %>
<BR>
</CENTER>
</FORM>
</BODY>
</HTML>

 

Source Code Listings


Previous Contents Next
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy