首页 cmnDBOpen.jsp
<%@page language="java" import="java.sql.*" %> <% Connection conn = null; try { //载入 MySQL 的 JDBC 驱动类 Class.forName("com.my
sql.jdbc.Driver"); //获得数据库连接 String sConn = "jdbc:
mysql://localhost/ch03?user=sa&;pass
word=11111"; conn = DriverManager.getConnection( sConn ); Statement stmt = null; ResultSet rs = null; %>
首页 cmnTipCount.jsp
<% //创建 Statement 对象 stmt = conn.createStatement(); //执行 SQL 语句 String query = "select count(*) from tip"; rs = stmt.executeQuery( query ); rs.next(); int iTipCount =rs.getInt(1); rs.close(); stmt.close(); %>
首页 cmnPageTop.jsp
<%@page contentType="text/html;charset=gbk" %>
| 数据库中共有 <%=iTipCount%> 条记录。 | 1 | | | |
首页 cmnPageBottom.jsp |
首页 cmnDBClose.jsp
<% } catch(Exception e) { out.clear(); out.println("Error Occured!!
" + e.getMessage()); e.printStackTrace(); } finally { //释放数据库连接
2
conn.close(); } %>
首页 index.jsp
<%@page contentType="text/html;charset=gbk" %> <%@ include file="/inc/cmnDBOpen.jsp" %> <%@ include file="/inc/cmnTipCount.jsp" %>
<%@ include file="/inc/cmnPageTop.jsp" %>
gotoAddPage();" alt="新增" onmouseout="this.src='img/menu_add1.gif'" onmouseover="this.src='img/menu_add2.gif'" menu_add1.gif? style="cursor:hand;"> |
|
<%@ include file="/inc/cmnPageBottom.jsp" %> <%@ include file="/inc/cmnDBClose.jsp" %>
输入界面: 输入界面:cmnGetCategory.jsp
<% //创建 Statement 对象 stmt = conn.createStatement(); String sCategorys = "";
3
String sSubCategorys = ""; //查询大分类 StringBuffer sGetCategorySQL = new StringBuffer(); sGetCategorySQL.append("select category_cd, ca