首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

Duplicate local variable sql错误?哪位高手来帮忙看一下,绝对给分

2013-09-11 
Duplicate local variable sql错误?谁来帮忙看一下,绝对给分这是错误提示:org.apache.jasper.JasperExcept

Duplicate local variable sql错误?谁来帮忙看一下,绝对给分
这是错误提示:
org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP

An   error   occurred   at   line:   31   in   the   jsp   file:   /chujuan1.jsp
Generated   servlet   error:
Duplicate   local   variable   sql

An   error   occurred   at   line:   31   in   the   jsp   file:   /chujuan1.jsp
Generated   servlet   error:
Duplicate   local   variable   sql


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

这是代码:
<SCRIPT   language= "javascript ">
function   backward()
{
            history.back();
}
function   teacher()
{
window.location= "UntitledFrameset-5.htm ";
}
</SCRIPT>
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   errorPage= " "   %>
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 添加成功 </title>
</head>

<body>
<%!
void   randomNum(int   a[],int   i,int   j)
{
  a[i]=1+(int)(Math.random()*j);
for(int   c=i-1;c> =0;c--)
        {
if(a[i]==a[c])
randomNum(a,i,j);
}
}
%>
<%
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
String   driver   =   "jdbc:odbc:try ";
String   user= "sa ";
String   password= " ";
Connection   conn   =   DriverManager.getConnection(driver, "sa ", " ");
Statement   stmt   =   conn.createStatement();
//读取表单内容
int   shijuanbianhao=Integer.parseInt(request.getParameter( "shijuanbianhao "));
System.out.println( '1 ');
String   sql= "SELECT   *   FROM   shijuan   where   shijuanbianhao= "+shijuanbianhao;
System.out.println( '2 ');
ResultSet   rs=stmt.executeQuery(sql);
System.out.println( '3 ');
if(rs.next())
{
int   xuanzeshumu=Integer.parseInt(request.getParameter( "xuanzeshumu "));
int   xuanzefenzhi=Integer.parseInt(request.getParameter( "xuanzefenzhi "));
int   panduanshumu=Integer.parseInt(request.getParameter( "panduanshumu "));


int   panduanfenzhi=Integer.parseInt(request.getParameter( "panduanfenzhi "));
int   zhuguanshumu=Integer.parseInt(request.getParameter( "zhuguanshumu "));
int   zhuguanfenzhi=0;
int   kaoshishijian=Integer.parseInt(request.getParameter( "kaoshishijian "));
int   i=0;
int   j[]=new   int   [30];
System.out.println( '4 ');
for(i=0;i <xuanzeshumu;i++)
{
    randomNum(j,i,30);
    sql= "SELECT   *   from   xuanzeti   where   id= "+j[i];
    rs=stmt.executeQuery(sql);
//     while(rs.next()){
rs.next();
int   id=Integer.parseInt(rs.getString( "id "));
String   timu=rs.getString( "tigan ");
System.out.println(timu);
String   timuleixing= "xuanzeti ";
String   sql= "update   shijuan   set   timu= ' "+timu+ " ',fenzhi= ' "+xuanzefenzhi+ " ',timuleixing= ' "+timuleixing+ " ',id= ' "+id+ " ',kaoshishijian= ' "+kaoshishijian+ " 'where   shijuanbianhao= ' "+shijuanbianhao+ " ' ";
stmt.executeUpdate(sql);
//}
}
System.out.println( '5 ');
for(i=0;i <panduanshumu;i++)
{
randomNum(j,i,20);
  sql= "SELECT   *   from   panduanti   where   id= "+j[i];
  rs=stmt.executeQuery(sql);
rs.next();
int   id=Integer.parseInt(rs.getString( "id "));
String   timu=rs.getString( "tigan ");
String   timuleixing= "panduanti ";
String   sql= "update   shijuan   set   timu= ' "+timu+ " ',fenzhi= ' "+panduanfenzhi+ " ',timuleixing= ' "+timuleixing+ " ',id= ' "+id+ " ',kaoshishijian= ' "+kaoshishijian+ " 'where   shijuanbianhao= ' "+shijuanbianhao+ " ' ";
stmt.executeUpdate(sql);
}
System.out.println( '6 ');
for(i=0;i <zhuguanshumu;i++)
{
randomNum(j,i,20);
    sql= "SELECT   *   from   zhuguanti   where   id= "+j[i];
    rs=stmt.executeQuery(sql);
//     while(rs.next()){
rs.next();
int   id=Integer.parseInt(rs.getString( "id "));
String   timu=rs.getString( "tigan ");
String   timuleixing= "zhuguanti ";
zhuguanfenzhi=(100-xuanzefenzhi*xuanzeshumu-panduanfenzhi*panduanshumu)/zhuguanshumu;
String   sql4= "update   shijuan   set   timu= ' "+timu+ " ',fenzhi= ' "+zhuguanfenzhi+ " ',timuleixing= ' "+timuleixing+ " ',id= ' "+id+ " ',kaoshishijian= ' "+kaoshishijian+ " 'where   shijuanbianhao= ' "+shijuanbianhao+ " ' ";
stmt.executeUpdate(sql4);
}
System.out.println( '7 ');
//rs.close();
stmt.close();
conn.close();
System.out.println( '8 ');
}
%>

<p> </p>
</body>
</html>


[解决办法]
你定义了两个变量都叫sql
[解决办法]
你在同一个页面定义了两个String局部变量sql,去掉第二个定义的String变量声明即可,或重命名第二个变量名
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html

热点排行