各位高手,不好意思,想请教一个简单的问题(因为我是菜鸟,嘿嘿),写了一个更新数据库信息的小程序,可是运行的时候老师出现下列问题:
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 12 in the jsp file: /theater/modifyloginout.jspGenerated servlet error:
[javac] Compiling 1 source fileC:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\theater\modifyloginout_jsp.java:76: unclosed string literal
String sql="update user_information set
^An error occurred at line: 12 in the jsp file: /theater/modifyloginout.jspGenerated servlet error:
C:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\theater\modifyloginout_jsp.java:77: unclosed character literal
password='"+password+"',passwordquestion='"+passwordquestion+"',passwordanswer='"+passwordanswer+"',theater_name='"+theater_name+"',city='"+city+"',email='"+email+"' where name='"+name+"'";
^
2 errors
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:127)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:458)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:553)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.我的程序是这样的:(省略了HTML部分)<%
final String DBDRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; //数据库驱动程序
final String DBURL = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=theater"; //URLConnection conn = null ;
ResultSet rs = null ;
Statement st=null;
PreparedStatement stat=null;
String name=request.getParameter("name");
String password=request.getParameter("password");
String passwordquestion=new String(request.getParameter("passwordquestion").getBytes("8859_1"));
String passwordanswer=new String(request.getParameter("passwordanswer").getBytes("8859_1"));
String theater_name=new String(request.getParameter("theater_name").getBytes("8859_1"));
String city=new String(request.getParameter("city").getBytes("8859_1"));
String email=request.getParameter("email");try
{
String sql="update user_information set
password='"+password+"',passwordquestion='"+passwordquestion+"',passwordanswer='"+passwordanswer+"',theater_name='"+theater_name+"',city='"+city+"',email='"+email+"' where name='"+name+"'";
Class.forName(DBDRIVER); //装载驱动程序
conn = DriverManager.getConnection(DBURL,"sa","admin") ;
st=conn.createStatement();
rs = st.executeQuery(sql) ;
}
catch(Exception e)
{
out.println(e);
}
%>在此拜谢各位了~~
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 12 in the jsp file: /theater/modifyloginout.jspGenerated servlet error:
[javac] Compiling 1 source fileC:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\theater\modifyloginout_jsp.java:76: unclosed string literal
String sql="update user_information set
^An error occurred at line: 12 in the jsp file: /theater/modifyloginout.jspGenerated servlet error:
C:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\theater\modifyloginout_jsp.java:77: unclosed character literal
password='"+password+"',passwordquestion='"+passwordquestion+"',passwordanswer='"+passwordanswer+"',theater_name='"+theater_name+"',city='"+city+"',email='"+email+"' where name='"+name+"'";
^
2 errors
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:127)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:458)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:553)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.我的程序是这样的:(省略了HTML部分)<%
final String DBDRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; //数据库驱动程序
final String DBURL = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=theater"; //URLConnection conn = null ;
ResultSet rs = null ;
Statement st=null;
PreparedStatement stat=null;
String name=request.getParameter("name");
String password=request.getParameter("password");
String passwordquestion=new String(request.getParameter("passwordquestion").getBytes("8859_1"));
String passwordanswer=new String(request.getParameter("passwordanswer").getBytes("8859_1"));
String theater_name=new String(request.getParameter("theater_name").getBytes("8859_1"));
String city=new String(request.getParameter("city").getBytes("8859_1"));
String email=request.getParameter("email");try
{
String sql="update user_information set
password='"+password+"',passwordquestion='"+passwordquestion+"',passwordanswer='"+passwordanswer+"',theater_name='"+theater_name+"',city='"+city+"',email='"+email+"' where name='"+name+"'";
Class.forName(DBDRIVER); //装载驱动程序
conn = DriverManager.getConnection(DBURL,"sa","admin") ;
st=conn.createStatement();
rs = st.executeQuery(sql) ;
}
catch(Exception e)
{
out.println(e);
}
%>在此拜谢各位了~~
语法:update table set field1=value1,field2=value2,...where fieldx=valuex
例子:update book set author=’babycrazy’ where bookno=’CF001’
String sql="update user_information set password='"+password+"',passwordquestion='"+passwordquestion+"',passwordanswer='"+passwordanswer+"',theater_name='"+theater_name+"',city='"+city+"',email='"+email+"' where name='"+name+"'";
看看数据库表中的类型。如果全部是string类型这样写就没有错。
如果是int类型的就不需要'"+dd+”'直接 +dd+就好了
Java/J2EE技术教程
String sql="update user_information set password='"+password+"',passwordquestion='"+passwordquestion+"',passwordanswer='"+passwordanswer+"',theater_name='"+theater_name+"',city='"+city+"',email='"+email+"' where name='"+name+"'";
碰到STRING类型的数据时应该用转义符,贴出我自己的给你看看。
PreparedStatement pstmt=conn.prepareStatement("update dishinfo set amount= "+"\'"+strNum+"\'"+"where id ="+" \' "+strId+" \' ");
你可以试试,不知到对你有没有帮助。
我建议在string sql=".....";
加 system.out.println("sql="+sql);
后面的字符串 格式错误
仔细看看有没有 漏掉什么或者是不是输入了 中文符号