<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%-- example.jsp --%> <%-- This JSP file shows you how to connect to a database with JDBC --%> Simple JDBC Connection >> Up

Simple JDBC Connection Example

<%-- As usual, import the classes in util (e.g., Date, String, etc.) --%> <%@page import="java.util.*"%> <%-- Import the Java class that handles the database access logic --%> <%@page import="uw.ischool.info340.labs.DbConnect"%> TBD <% String sCode = "MA"; /* Initialize the class that manages the database */ DbConnect db = new DbConnect(); db.init(); /* Check if the connection is up */ String info = db.isConnected(); %> Connection information

<%=info%>
<% /* Now execute the query */ db.setStateCode(sCode); db.runQuery(); %> The query is: <%= sCode %>.

The result is: <%= db.getStateName() %>


View Source