全面解析JDBC
图2 查询主页面 本文来自织梦
query.htm将用户选择查询的数据库表和查询条件发送给demo_query.jsp,由jsp文件完成数据库查询操作和查询结果集的返回及显示,其功能代码如下:
内容来自dedecms<html>
<body>
<%
String sqlStatement;
String sqlField = "";
String whichTable = "";
String whereClause = "";
String queryNo = "";
String queryName = "";
%>
<jsp:useBean id="DBConn" class="dbaccess.DBConnBean" scope="page"/>
<jsp:useBean id="DBBean" class="dbaccess.DBQueryBean" scope="page"/>
<hr>
<!--test JavaBean-->
<%
if (DBConn == null||DBBean == null){
out.println("JavaBean not found!");
return;
}
%>
<!--try db_demo connection-->
<%
try{
DBConn.Connect();
}catch(Exception e){
out.println(e.getMessage());
}
%>
<!--prepare sql statement-->
<%
String queryRequest = request.getParameter("rb_request");
//out.println("queryRequest:" queryRequest);
String whichCB = "";
if (queryRequest.equals("1")){
whichCB = "ck_jhcg";
whichTable = "jhcg_table";
queryNo = request.getParameter("ed_jhcg_no");
queryName = request.getParameter("ed_jhcg_name");
if (!queryNo.equals(""))
whereClause = " where good_no=" "'" queryNo "'";
if (!queryName.equals("")){
if (!queryNo.equals(""))
whereClause = " and good_name=" "'" queryName "'";
else whereClause = " where good_name=" "'" queryName "'";
}
}
if (queryRequest.equals("2")){
whichCB = "ck_kctj";
whichTable = "kctj_table";
queryNo = request.getParameter("ed_kctj_no");
queryName = request.getParameter("ed_kctj_name");
if (!queryNo.equals(""))
whereClause = " where good_no=" "'" queryNo "'";
if (!queryName.equals("")){
if (!queryNo.equals(""))
whereClause = " and good_name=" "'" queryName "'";
文章评论
共有位Admini5网友发表了评论 查看完整内容