throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
String account = request.getParameter("account1");
String password = request.getParameter("password1");
Connection conn = null;
Statement stmt = null;
try{
// ��̬������ݿ����
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test", "root", "123456");
String sql = "INSERT INTO userlogin ( name,passward ) VALUES ( '"+account+"', '"+password+"' )";
stmt = conn.createStatement();
stmt.executeUpdate(sql);
}catch(Exception e){
e.printStackTrace();
}finally{
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
type Exception report
message
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
com.lmc.homework.test.ServletInsert.doPost(ServletInsert.java:37)
javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.41 logs.
37为空,说明stam为空,也就说明try里面没有正常执行。而这个错误你没有截出来,不好定位
stmt.close()空指针那就是 stmt为空了呀