部分代码如下:
<%
Connection conn = linejdbc.getopenConnection();
PreparedStatement p = conn.prepareStatement( "select max(id) from tiku ");
ResultSet rp = p.executeQuery();
rp.next();
ResultSet rs=null;
int maxid=rp.getInt(1);
int num;
int j=0;
int i;
int randnum[]=new int[50];
boolean isexsit=false;
for(num=0;num <50;num++)
{
randnum[num]=0;
}
Random rand = new Random();
while (true)
{
isexsit=false;
i = rand.nextInt(maxid);
//判断随机数是否重复
for(num=0;num <j;num++)
{
if (randnum[num]==i)
{
isexsit=true;
break;
}
}
if (!isexsit)
{
p = conn.prepareStatement( "select * from tiku where id=? ");
p.setInt(1,i);
rs=p.executeQuery();
if (rs.next())
{
id=rs.getInt( "id ");
Question = rs.getString( "question ");
KeyA = rs.getString( "keya ");
KeyB = rs.getString( "keyb ");
KeyC = rs.getString( "keyc ");
KeyD = rs.getString( "keyd ");
Answer = rs.getString( "answer ");
%>
错误提示:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: n must be positive
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.IllegalArgumentException: n must be positive
java.util.Random.nextInt(Random.java:248)
org.apache.jsp.begin_jsp._jspService(begin_jsp.java:244)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.30 logs.
请高手帮忙解决一下,急!!
------解决方法--------------------------------------------------------
i = rand.nextInt(maxid);
这个方法的参数要是一个整数 maxid打印出来看看 是不是一个负数