University of Cincinnati logo and link  
JSP JDBC Source, Screen Capture
 
  UC ingot The quick & dirty JSP I wrote is:
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
 <META http-equiv="Expires" content="0" > </META> 
 <title>Insert Data</title> 
</HEAD> 
<BODY> 

<P align="center">
 <font size="7"> 
Quick & Dirty Database Call 
 </font> 
</P> 
  
  

<%@ page import = "java.sql.*" %> 
<table border =1> 
<% 
  

 // Connection info. 
  
 Class.forName("com.mysql.jdbc.Driver").newInstance(); 
  
 java.sql.Connection conn; 
  
 conn = DriverManager.getConnection("jdbc:mysql://localhost/students"); 

 Statement stmt = conn.createStatement();

 // Do the select. 

 ResultSet rs = stmt.executeQuery("Select * from students");

 int recordNo = 0;

 while(rs.next()) {
  recordNo++; 
  %> 
  <tr> 
   <td colspan = 4> 
   Record # <%=recordNo%> 
   </td> 
  <tr> 
  <tr> 
   <td>Name: <%=rs.getString("Name")%></td> 
    <td>ID: <%=rs.getString("BearcatID")%></td> 
   <td>Gender: <%=rs.getString("Gender")%></td> 
   <td>Major: <%=rs.getString("Major")%></td> 
   <td>College ID: <%=rs.getString("CollegeId")%></td> 
  </tr> 
  <% 
 } 

%>
</table> 

Database connection complete.

</BODY>
</HTML> 

 UC ingot  web.xml


<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
</web-app>

UC ingotTomcat directory structure:

jsp file:   webapps/advjava/
web.xml file:  webapps/advjava/WEB-INF/
all jar files:  webapps/advjava/WEB-INF/lib/ 


UC ingotAnd the output:

(For more information on servlets and JSPs, see the slides from Java II)

 SQL Explained