Using the JDBC in JavaServer Pages

Now that we have covered the basics of using the JDBC, let's look at how you can integrate it into a JSP. It is really very simple. Listing 4.5 contains a sample JSP that performs a query on the previously used Titles table.

Code Listing 4.5. JDBCExample.jsp
 <HTML> <HEAD> <TITLE>JSP JDBC Example 1</TITLE> </HEAD> <BODY> <!-- Set the scripting language to java and --> <!-- import the java.sql package --> <%@ page language="java" import="java.sql.*" %> <% Connection con = null; try { // Load the Driver class file Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Make a connection to the ODBC datasource Movie Catalog con = DriverManager.getConnection("jdbc:odbc:Movie Catalog", "", ""); // Create the statement ...

Get Pure Java Server Pages™ 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.