空指针问题
读取XML文件并且存储到数据库表中:
<%
String ID,WINNER_ID,PERFORMANCE;
String FILE_NAME,PRINCIPLE,FILE_TIME,REMARK,WINNER_GRADE,OPG_NAME,RESULT,sql;
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:MyOrcal", "scott","tiger");
Statement stmt=conn.createStatement();
DocumentBuilderFactory DBF=DocumentBuilderFactory.newInstance();
DocumentBuilder DB=DBF.newDocumentBuilder();
Document DOC=DB.parse("SQLServer.xml");
NodeList N1=DOC.getElementsByTagName("ROW");
for(int i=0;i<N1.getLength();i++)
{
Element E=(Element)N1.item(i);
ID=E.getElementsByTagName("ID").item(0).getFirstChild().getNodeValue();
FILE_NAME=E.getElementsByTagName("FILE_NAME").item(0).getFirstChild().getNodeValue();
PRINCIPLE=E.getElementsByTagName("PRINCIPLE").item(0).getFirstChild().getNodeValue();
REMARK =E.getElementsByTagName("REMARK").item(0).getFirstChild().getNodeValue();
WINNER_ID=E.getElementsByTagName("WINNNER_ID").item(0).getFirstChild().getNodeValue();
WINNER_GRADE=E.getElementsByTagName("WINNER_GRADE").item(0).getFirstChild().getNodeValue();
OPG_NAME=E.getElementsByTagName("OPG_NAME").item(0).getFirstChild().getNodeValue();
PERFORMANCE =E.getElementsByTagName("PERFORMANCE").item(0).getFirstChild().getNodeValue();
RESULT =E.getElementsByTagName("RESULT").item(0).getFirstChild().getNodeValue();
FILE_TIME=E.getElementsByTagName("FILE_TIME").item(0).getFirstChild().getNodeValue();
sql="insert into SCOTT.XMCG values('"+ID+"','"+FILE_NAME+"','"+PRINCIPLE+"','"+REMARK+"','"+WINNER_ID+"','"+WINNER_GRADE+"','"+OPG_NAME+"','"+PERFORMANCE+"','"+RESULT+"','"+FILE_TIME+"')";
stmt.executeUpdate(sql);
}
System.out.println("已经将XML数据插入到数据库中");
stmt.close();
conn.close();
%>
错误信息:root cause
java.lang.NullPointerException org.apache.jsp.xml_jsp._jspService(xml_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
------解决方案--------------------xml_jsp.java:79找到生成的servlet看看79行
路径例如D:\Tomcat\work\Catalina\localhost\test\org\apache\jsp
------解决方案--------------------s是不是
sql="insert into SCOTT.XMCG values('"+ID+"','"+FILE_NAME+"','"+PRINCIPLE+"','"+REMARK+"','"+WINNER_ID+"','"+WINNER_GRADE+"','"+OPG_NAME+"','"+PERFORMANCE+"','"+RESULT+"','"+FILE_TIME+"')";
这一句有问题啊,是不是应该写上对应的字段