导航菜单
首页 > 外文翻译 > Introduction to JDBC

Introduction to JDBC

: 0px; margin-bottom: 0px; -ms-text-justify: inter-ideograph;"><jsp:scriptlet>

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>

全套资源,请扫描下方二维码获取

Top