0

このエラーが発生する理由..

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();
                                    }
                                }
4

1 に答える 1

1

最終ブロックは次のようになります。

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

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


   if(st != null) {
    st.close();
   }
  } catch (SQLException e) {
  }//end try
}//end finally
于 2013-03-29T09:05:25.277 に答える