Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 路径为[/jaagrut]的上下文中Servlet[com.jagrut.GroupServlet]的Servlet.service()引发异常_Java_Mysql_Servlets_Jdbc - Fatal编程技术网

Java 路径为[/jaagrut]的上下文中Servlet[com.jagrut.GroupServlet]的Servlet.service()引发异常

Java 路径为[/jaagrut]的上下文中Servlet[com.jagrut.GroupServlet]的Servlet.service()引发异常,java,mysql,servlets,jdbc,Java,Mysql,Servlets,Jdbc,为什么会出现这个错误 Mar 29, 2013 2:04:26 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [com.jagrut.GroupServlet] in context with path [/jaagrut] threw exception java.lang.NullPointerException at com.

为什么会出现这个错误

Mar 29, 2013 2:04:26 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [com.jagrut.GroupServlet] in context with path          [/jaagrut] threw exception
   java.lang.NullPointerException
at com.jagrut.GroupServlet.doPost(GroupServlet.java:170)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
这是密码

 try {  
                        String queryString = "INSERT INTO groups(course_id,group_name,location,batch_no)"
                                + " VALUES ('"
                                + ccode
                                + "','"
                                + group
                                + "','"
                                + loc
                                + "','" + batch + "')";



                                st = con.createStatement();

                                last_id = st.executeUpdate(queryString);

                                 System.out.println(">>>>>>>llll" + last_id);
                                /* Getrting Group_id from groups table */

                                 if(last_id == 0){

                                        out.print("Group Already Available.");
                                        //return;
                                 }

                                    try{
                                    st1 = con.createStatement();
                                    rs1 = st1.executeQuery("SELECT group_id from groups Where group_name='"+ group + "'");
                                    while (rs1.next()) {
                                    group_id = rs1.getInt(1);
                                    }
                                    System.out.print(">>>>>>>" + group_id);
                                    /* Inserting DATA to Student Group */
                                    }catch (SQLException ex1) {

                                        System.out.print("Unable to Create Group.Duplicate Entry ");
                                        ex1.printStackTrace();

                                    }
                                    try {
                                            stmt1 = con.createStatement();
                                            for (int i = 0; i < stud.length; i++) {
                                                //System.out.println(stud[i]);
                                                String sql = "Insert into student_group(group_id,s_id)Values('" + group_id + "','" + stud[i] + "')";
                                                stmt1 = con.createStatement();
                                                updateQuery = stmt1.executeUpdate(sql);
                                            }
                                        } catch (Exception ex1) {

                                            out.println("Unable to Insert Student Into Group.");
                                            ex1.printStackTrace();
                                        }

                                        /* Inserting teacher into the group */
                                        try {
                                        String query = "Insert into teacher_group(group_id,t_id,join_date)Values('" + group_id + "','" + teacher + "','" + sqlDate + "')";

                                                st2 = con.createStatement();

                                                updateQuery = st2.executeUpdate(query);

                                                if (updateQuery != 0) {
                                                    out.println("Group Created Successfully");
                                                }
                                            } catch (Exception ex2) {

                                                out.println("Unable to Insert Teacher Into Group.");
                                                ex2.printStackTrace();
                                            }
                                        } catch (SQLException ex) {
                                            out.print("Group Already Available.");
                                                System.out.print("Unable to Create Group.Duplicate Entry ");
                                                ex.printStackTrace();

                                            }
                                        finally {
                                             // close all the connections.
                                            try {
                                                rs.close();
                                                stmt.close();
                                                st.close();
                                                rs1.close();
                                                stmt1.close();
                                                st1.close();
                                                st2.close();
                                                con.close();
                                            } catch (SQLException e) {


                                        e.printStackTrace();
                                    }
                                }

最后一块应该是:

finally {
   try {
   if(rs != null) {
    rs.close();
   }

  if(stmt != null) {
     stmt.close();
  }


   if(st != null) {
    st.close();
   }
  } catch (SQLException e) {
  }//end try
}//end finally

最后一块最后一块…谢谢你。。非常感谢..@user1891823如果有用,请将其标记为答案。