Class.forName("org.gjt.mm.mysql.Driver");
Connection connection =
DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "", "");
Statement statement = connection.createStatement();
int changed =
statement.executeUpdate("update counters set hitCount = hitCount + 1 " +
"where page like '" + request.getRequestURI() + "'");
if (changed == 0) statement.executeUpdate("insert counters(page) values('" +
request.getRequestURI() + "')");
ResultSet rs =
statement.executeQuery("select hitCount from counters where page like '" +
request.getRequestURI() + "'");
rs.next();
int hitCount = rs.getInt(1);
statement.close();
connection.close();
</jsp:scriptlet>
<HTML>
<HEAD>
<TITLE>JDBC scriptlet example</TITLE>
</HEAD>
<BODY>
<P>This page has been hit
<jsp:expression>hitCount</jsp:expression>
times. The page counter is implemented by a JSP scriptlet calling
the JDBC package directly.</P>
</BODY>
</HTML>