问题如下:
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 70 in the jsp file: /JavaBeanTest/Vote.jsp
The method executeUpdate(String) is undefined for the type DataBase
67: ++count;
68: //鏇存敼鏁版嵁搴撳唴瀹�
69: String s1 = "update vote set count = " + count + " where id = " + s;
70: int n = DataBase.executeUpdate(s1 );
71: if ( n > 0)
72: {
73: out.print( "鎶曠エ鎴愬姛!!");
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:95)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:367)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:345)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:342)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
我的JSP页面:
<%
/*处理投票结果*/
String s = request.getParameter("a");
/*未投票,不作任何处理*/
if (s != null)
{}
/*投票后,更改数据库*/
else
{
rs.next();
rs = DataBase.executeQuery("select count from vote where id = " + s);
int count = Integer.parseInt(rs.getString(1));
++count;
//更改数据库内容
String s1 = "update vote set count = " + count + " where id = " + s;
int n = DataBase.executeUpdate(s1 );
if ( n > 0)
{
out.print( "投票成功!!");
}
}
%>
DataBase类:
/*数据库连接类*/
package com.db;
import java.sql.*;public class DataBase {
private static Connection con = null;
private static Statement st = null;
private static ResultSet rs = null;
/*建立桥接器函数*/
private static void forName()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
public static ResultSet executeQuery(String str)
{
//建立桥接器
forName();
try
{
//建立连接
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test1", "root", "");
//建立SQL对象
st = con.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
//执行查询
rs = st.executeQuery(str);
}
catch (SQLException e)
{
e.printStackTrace();
}
return rs;
}
public static int executeUpdate(String str)
{
int n = 0;
//建立桥接器
forName();
try
{
//建立连接
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test1", "root", "");
//建立SQL对象
st = con.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
//执行查询
n = st.executeUpdate(str);
}
catch (SQLException e)
{
e.printStackTrace();
}
return n;
}}
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 70 in the jsp file: /JavaBeanTest/Vote.jsp
The method executeUpdate(String) is undefined for the type DataBase
67: ++count;
68: //鏇存敼鏁版嵁搴撳唴瀹�
69: String s1 = "update vote set count = " + count + " where id = " + s;
70: int n = DataBase.executeUpdate(s1 );
71: if ( n > 0)
72: {
73: out.print( "鎶曠エ鎴愬姛!!");
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:95)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:367)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:345)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:342)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
我的JSP页面:
<%
/*处理投票结果*/
String s = request.getParameter("a");
/*未投票,不作任何处理*/
if (s != null)
{}
/*投票后,更改数据库*/
else
{
rs.next();
rs = DataBase.executeQuery("select count from vote where id = " + s);
int count = Integer.parseInt(rs.getString(1));
++count;
//更改数据库内容
String s1 = "update vote set count = " + count + " where id = " + s;
int n = DataBase.executeUpdate(s1 );
if ( n > 0)
{
out.print( "投票成功!!");
}
}
%>
DataBase类:
/*数据库连接类*/
package com.db;
import java.sql.*;public class DataBase {
private static Connection con = null;
private static Statement st = null;
private static ResultSet rs = null;
/*建立桥接器函数*/
private static void forName()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
public static ResultSet executeQuery(String str)
{
//建立桥接器
forName();
try
{
//建立连接
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test1", "root", "");
//建立SQL对象
st = con.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
//执行查询
rs = st.executeQuery(str);
}
catch (SQLException e)
{
e.printStackTrace();
}
return rs;
}
public static int executeUpdate(String str)
{
int n = 0;
//建立桥接器
forName();
try
{
//建立连接
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test1", "root", "");
//建立SQL对象
st = con.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
//执行查询
n = st.executeUpdate(str);
}
catch (SQLException e)
{
e.printStackTrace();
}
return n;
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货