0 java mysql myeclipse servlets
我正在为一个只有5个问题的在线考试创建一个3层Web应用程序.我使用html并设计了一个servlet来将数据发布到mysql数据库,我将其命名为'test',表格为'st1'.我使用MyEclipse Blue 8.6.1,它有一个内置的MyEclipse Tomcat 6.0.13.doPost()方法中servlet的编码如下:
try
{
String url="jdbc:mysql://localhost:3306/test";
Class.forName("com.mysql.jdbc.Driver");
connect=DriverManager.getConnection(url,"root","root");
message="Connection Sucessfull";
}
catch(ClassNotFoundException cnfex){
cnfex.printStackTrace();
}
catch(SQLException sqlex){
sqlex.printStackTrace();
}
catch(Exception excp){
excp.printStackTrace();
}
seat_no=request.getParameter("Seat_No");
name=request.getParameter("Name");
ans1=request.getParameter("group1");
ans2=request.getParameter("group2");
ans3=request.getParameter("group3");
ans4=request.getParameter("group4");
ans5=request.getParameter("group5");
if(ans1.equals("True"))
Total+=2;
if(ans2.equals("False"))
Total+=2;
if(ans3.equals("True"))
Total+=2;
if(ans4.equals("False"))
Total+=2;
if(ans5.equals("False"))
Total+=2;
try
{
Statement stmt=connect.createStatement();
String query="INSERT INTO st1("+"seat_no,name,marks"+")VALUES('"+seat_no+"','"+name+"','"+Total+"')";
stmt.executeUpdate(query);
stmt.close();
}
Run Code Online (Sandbox Code Playgroud)
当我编译应用程序时,我不断收到异常:
HTTP Status 500 -
type Exception report
message:
description The server encountered an internal error () that prevented it from fulfilling this request.
exception :
java.lang.NullPointerException
s3.doPost(s3.java:52)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note :The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs
Run Code Online (Sandbox Code Playgroud)
但我找不到任何可用于MyEclipse Tomcat 6.0.13的日志.任何人都可以帮我克服这个例外吗?这是我的学术项目!提前致谢 !!
| 归档时间: |
|
| 查看次数: |
1186 次 |
| 最近记录: |