【发布时间】:2015-03-27 09:04:49
【问题描述】:
我已经尝试了一些东西,但我无法获得输出,而且它花费了太多时间来显示输出屏幕...... 例如:在我的情况下,输出应该包含一个表,其输出是根据我的程序生成的,但是它花费了太多时间来执行操作,之后它只显示表标题....
我用谷歌搜索了这个,但我找不到合适的想法......
感谢任何可以提供帮助的人。
这是我的代码:
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
ResultSet result;
String dat,d,s,i,r;
int numcols,index,ans = 0;
ResultSetMetaData resultMd;
String rs = null;
d= request.getParameter("name");
s= request.getParameter("gen");
i= request.getParameter("indi");
r= request.getParameter("rea");
response.setContentType("text/html");
PrintWriter out=response.getWriter();
if(d!=null && i==null && r==null)
ans=1;
else if(d!=null && i==null && r!=null)
ans=2;
else if(d!=null && i!=null && r!=null)
ans=3;
else if(d==null && i!=null && r!=null)
ans=4;
else if(d==null && i==null && r!=null)
ans=5;
else if(d!=null && i!=null && r==null)
ans=6;
else if(d==null && i!=null && r==null)
ans=7;
switch(ans)
{
case 1:
rs="SELECT d.gndr_cod,d.age,d.wt,d.reporter_country,dr.drug_name,i.indi_pt,o.outc_cod,r.pt from demo d,drug dr,indi i,outc o,reac r where dr.drug_name='"+d+"' and d.gndr_cod='"+s+"' limit 25";
break;
case 2:
rs="SELECT d.gndr_cod,d.age,d.wt,d.reporter_country,dr.drug_name,i.indi_pt,o.outc_cod,r.pt from demo d,drug dr,indi i,outc o,reac r where dr.drug_name='"+d+"' and r.pt='"+r+"' and d.gndr_cod='"+s+"' limit 25";
break;
case 3:
rs="SELECT d.gndr_cod,d.age,d.wt,d.reporter_country,dr.drug_name,i.indi_pt,o.outc_cod,r.pt from demo d,drug dr,indi i,outc o,reac r where dr.drug_name='"+d+"' and r.pt='"+r+"' and i.indi_pt='"+i+"' and d.gndr_cod='"+s+"' limit 25";
break;
case 4:
rs="SELECT d.gndr_cod,d.age,d.wt,d.reporter_country,dr.drug_name,i.indi_pt,o.outc_cod,r.pt from demo d,drug dr,indi i,outc o,reac r where r.pt='"+r+"' and i.indi_pt='"+i+"' and d.gndr_cod='"+s+"' limit 25";
break;
case 5:
rs="SELECT d.gndr_cod,d.age,d.wt,d.reporter_country,dr.drug_name,i.indi_pt,o.outc_cod,r.pt from demo d,drug dr,indi i,outc o,reac r where r.pt='"+r+"' and d.gndr_cod='"+s+"' limit 25";
break;
case 6:
rs="SELECT d.gndr_cod,d.age,d.wt,d.reporter_country,dr.drug_name,i.indi_pt,o.outc_cod,r.pt from demo d,drug dr,indi i,outc o,reac r where dr.drug_name='"+d+"' and i.indi_pt='"+i+"' and d.gndr_cod='"+s+"' limit 25";
break;
case 7:
rs="SELECT d.gndr_cod,d.age,d.wt,d.reporter_country,dr.drug_name,i.indi_pt,o.outc_cod,r.pt from demo d,drug dr,indi i,outc o,reac r where i.indi_pt='"+i+"' and d.gndr_cod='"+s+"' limit 25";
break;
}
out.print("<html>");
out.print("<head><title>Results</title></head>");
out.print("<body>");
try
{
result=mystmt.executeQuery(rs);
resultMd=result.getMetaData();
numcols=resultMd.getColumnCount();
out.print("<table border='1' width='100%'>");
out.print("<tr><th>Drug Name</th><th>Sex</th><th>Age</th><th>Weight</th><th>Country</th>");
out.print("<th>Indication</th><th>Reaction</th><th>Outcome</th>");
out.print("</tr>");
while(result.next())
{
out.print("<tr>");
for(index=0; index<=numcols;index++)
{
dat=result.getString(index);
out.print("<td>" +dat+"</td>");
}
out.print("</tr>");
}
out.print("</table>");
}
catch(Exception e)
{
e.printStackTrace();
}
out.print("</body></html>");}
【问题讨论】:
-
签入调试器或打印
numcols得到的内容。还要检查您的服务器日志中是否有任何堆栈跟踪。而index的getString()从 1 开始,而不是从 0 开始。