急急急急急急急急.......................写一个jsp中的根据条件查询
根据两个条件查询
只有第一个可以查出结果
第二个查不出
两个一起也查不出
程序如下
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" import="javax.swing.JOptionPane" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>数据处理</title>
</head>
<body>
<%
String section=request.getParameter("section_no");
String group=request.getParameter("group");
int section_no= -100;
boolean flag = false;
if(section!=null && !section.equals(""))
{section_no = Integer.parseInt(section);
flag = true;
}
String guiz[]=new String[500];
String bianm[]=new String[500];
String mingc[]=new String[500];
String weis[]=new String[500];
String shuie[]=new String[500];
String hans[]=new String[500];
String cux[]=new String[500];
Connection conn=null;
Statement Stmt=null;
ResultSet rs=null;
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@194.1.1.236:1521:css";
String user="stdba";
String password="glq73hzz";
conn=DriverManager.getConnection(url,user,password);
Stmt=conn.createStatement();
String strquery="select e.group_no as group_no,e.name as name,sum(round(b.sales_amnt_td,2)) as sales_amnt_td, round(sum(round(b.sales_amnt_td_p,2)-round(b.sales_amnt_td_c,2)),2) as sales_amnt_td_p, round(sum(round(b.sales_amnt_td_c,2)),2) as sales_amnt_td_c,sum(round(b.prof_amnt_td,2)) as prof_amnt_td,e.section_no from items a,items_sales b,items_recpt c,vat d,store_section_groups e,vat f where a.item_no=b.item_no(+)and a.item_no=c.item_no(+) and a.sell_vat=d.vat_no(+) and a.buy_vat=f.vat_no and a.group_no=e.group_no and a.section_no=e.section_no and a.status>0 and (b.sales_amnt_td<>0 or a.stock_adj<>0 or c.recpt_td<>0 or a.start_stock<>0) ";
if(flag)
{strquery = strquery.concat("and e.section_no='"+section+"'");
if(group!=null)
strquery = strquery.concat(" and e.group_no='"+group+"'");
}
else
if(group!=null){
strquery = strquery.concat("and e.group_no='"+group+"'");}
else {strquery = strquery.concat("and e.section_no='"+section+"'");}
strquery = strquery.concat(" group by e.group_no,e.name,e.section_no");
try{
rs=Stmt.executeQuery(strquery);
}
catch(Exception e)
{
System.out.print(e+"数据库连接失败!");
}
int i=0;
%>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr align="center">
<td width="3%" rowspan="3"> </td>
<td width="18%" rowspan="3">柜组</td>
<td colspan="2" rowspan="2">柜台</td>
<td height="29" colspan="4">销售金额</td>
</tr>
<tr>
<td height="29" colspan="3" align="center">正常</td>
<td width="13%" rowspan="2" align="center">促销</td>
</tr>
<tr>
<td width="15%" height="37" align="center">编码</td>
<td width="15%" align="center">名称</td>
<td width="15%" align="center">weis</td>
<td width="12%" align="center">税额</td>
<td width="12%" align="center">含税</td>
</tr>
<% if(rs!=null)
if(rs.next())
{ do
{
guiz[i]=rs.getString(7);
bianm[i]=rs.getString(1);
mingc[i]=rs.getString(2);
weis[i]=rs.getString(3);
shuie[i]=rs.getString(4);
hans[i]=rs.getString(5);
cux[i]=rs.getString(6);
%>
<tr>
<td> </td>
<td><%=guiz[i]%></td>
<td><%=bianm[i]%></td>
<td><%=mingc[i]%></td>
<td><%=weis[i]%></td>
<td bgcolor="#FFFFE1"><%=shuie[i]%></td>
<td bgcolor="#FFFFE1"><%=hans[i]%></td>
<td bgcolor="#DFF9FF"><%=cux[i]%></td>
</tr>
<%
i++;
}while(rs.next());
}
%>
</table>
</body>
</html>
<%
System.out.println("database link sucess!");
Stmt.close();
conn.close();
%>帮帮忙!先谢了
根据两个条件查询
只有第一个可以查出结果
第二个查不出
两个一起也查不出
程序如下
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" import="javax.swing.JOptionPane" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>数据处理</title>
</head>
<body>
<%
String section=request.getParameter("section_no");
String group=request.getParameter("group");
int section_no= -100;
boolean flag = false;
if(section!=null && !section.equals(""))
{section_no = Integer.parseInt(section);
flag = true;
}
String guiz[]=new String[500];
String bianm[]=new String[500];
String mingc[]=new String[500];
String weis[]=new String[500];
String shuie[]=new String[500];
String hans[]=new String[500];
String cux[]=new String[500];
Connection conn=null;
Statement Stmt=null;
ResultSet rs=null;
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@194.1.1.236:1521:css";
String user="stdba";
String password="glq73hzz";
conn=DriverManager.getConnection(url,user,password);
Stmt=conn.createStatement();
String strquery="select e.group_no as group_no,e.name as name,sum(round(b.sales_amnt_td,2)) as sales_amnt_td, round(sum(round(b.sales_amnt_td_p,2)-round(b.sales_amnt_td_c,2)),2) as sales_amnt_td_p, round(sum(round(b.sales_amnt_td_c,2)),2) as sales_amnt_td_c,sum(round(b.prof_amnt_td,2)) as prof_amnt_td,e.section_no from items a,items_sales b,items_recpt c,vat d,store_section_groups e,vat f where a.item_no=b.item_no(+)and a.item_no=c.item_no(+) and a.sell_vat=d.vat_no(+) and a.buy_vat=f.vat_no and a.group_no=e.group_no and a.section_no=e.section_no and a.status>0 and (b.sales_amnt_td<>0 or a.stock_adj<>0 or c.recpt_td<>0 or a.start_stock<>0) ";
if(flag)
{strquery = strquery.concat("and e.section_no='"+section+"'");
if(group!=null)
strquery = strquery.concat(" and e.group_no='"+group+"'");
}
else
if(group!=null){
strquery = strquery.concat("and e.group_no='"+group+"'");}
else {strquery = strquery.concat("and e.section_no='"+section+"'");}
strquery = strquery.concat(" group by e.group_no,e.name,e.section_no");
try{
rs=Stmt.executeQuery(strquery);
}
catch(Exception e)
{
System.out.print(e+"数据库连接失败!");
}
int i=0;
%>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr align="center">
<td width="3%" rowspan="3"> </td>
<td width="18%" rowspan="3">柜组</td>
<td colspan="2" rowspan="2">柜台</td>
<td height="29" colspan="4">销售金额</td>
</tr>
<tr>
<td height="29" colspan="3" align="center">正常</td>
<td width="13%" rowspan="2" align="center">促销</td>
</tr>
<tr>
<td width="15%" height="37" align="center">编码</td>
<td width="15%" align="center">名称</td>
<td width="15%" align="center">weis</td>
<td width="12%" align="center">税额</td>
<td width="12%" align="center">含税</td>
</tr>
<% if(rs!=null)
if(rs.next())
{ do
{
guiz[i]=rs.getString(7);
bianm[i]=rs.getString(1);
mingc[i]=rs.getString(2);
weis[i]=rs.getString(3);
shuie[i]=rs.getString(4);
hans[i]=rs.getString(5);
cux[i]=rs.getString(6);
%>
<tr>
<td> </td>
<td><%=guiz[i]%></td>
<td><%=bianm[i]%></td>
<td><%=mingc[i]%></td>
<td><%=weis[i]%></td>
<td bgcolor="#FFFFE1"><%=shuie[i]%></td>
<td bgcolor="#FFFFE1"><%=hans[i]%></td>
<td bgcolor="#DFF9FF"><%=cux[i]%></td>
</tr>
<%
i++;
}while(rs.next());
}
%>
</table>
</body>
</html>
<%
System.out.println("database link sucess!");
Stmt.close();
conn.close();
%>帮帮忙!先谢了
解决方案 »
- 怎样将Excel文件导入导出数据库(在JSP环境下Java代码)
- jsp applet运行问题
- 类型转换问题
- 怎样将多个值放到一个数组了,然后怎么比较两个数组是否相等?
- JSP新手跪求,已经开第二贴了,高手来看看啊
- 用JDOM生成的XML再次写入的时候把原来信息覆盖了
- 如何知道jsp中实际上使用的buffer大小?
- 关于<s:action>的一个问题,不知道你们有没有遇到过,帮忙解决一下
- 现有两个表Ta,Tb(问题不太好描述,进来看吧!
- 用jbuilder5.0与weblogic6.0开发jsp的问题
- Suggest Framework 输入提示应用出错!
- 有谁知道江西南昌的开启财智it培训如何
另外,你可以把你的SQL直接在数据库里执行看看有没有结果?
{strquery = strquery.concat("and e.section_no='"+section+"'");
if(group!=null)
strquery = strquery.concat(" and e.group_no='"+group+"'");
}
else
if(group!=null){
strquery = strquery.concat("and e.group_no='"+group+"'");}
else {strquery = strquery.concat("and e.section_no='"+section+"'");}
strquery = strquery.concat(" group by e.group_no,e.name,e.section_no");