回 帖 发 新 帖 刷新版面

主题:求救 急 急 急!!!!!!!!!!!!关于数据库连接的

以下是我编的一个JSP程序 功能是同过一个客户页面访问一个数据库
dbJsp.jsp
<%@ page contentType="text/html; charset=GBK" %>
<html>
<%@ page language="java" import="java.sql.*"%>
<head>
<%
  String tableName=request.getParameter("tableName");
%>
<title><%=tableName%>表中数据</title>


</head>
<body bgcolor="#FFFFFF" text="#000000">
<%
  Connection connection=null;
  ResultSet rs=null;
  Statement statement=null;
  if(tableName.equals("studentbase")){
     out.println("<h2 align=center>学生基本信息表中的数据</h2>");
  }
  else if(tn.equals("studentaddress")){
     out.println("<h2 align=center>学生地址表中的数据</h2>");
  }
  else{
     out.println("<h2 align=center>选课信息表中的数据</h2>");
  }
  try{
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     String url="jdbc:odbc:student";
     connection=DriverManager.getConnection(url);
     statement=connection.createStatement();
     String sql="select * from"+tableName;
     rs=statement.executeQuery(sql);
     ResultSetMetaData rsData=rs.getMetaData();
     out.println("<table width=75% border=1 align=center><tr>");
     for(int i=1;i<=rsData.getColumnCount();i++){
         out.println("<td>"+rsData.getColumnLabel(i)+"</td>");
     }
     out.println("</tr>");
     while(rs.next()){
         out.println("<tr>");
        for (int i=1;i<=rsData.getColumnCount();i++){
              out.println("<td>"+rs.getString(i)+"</td>");
        }
         out.println("</tr>");
     }
     out.println("</table>");
  }
  catch(SQLException ex){
      System.out.println("\nERROR:-------SQLException----------\n");
      while(ex!=null){
           System.out.println ("Message:"+ex.getMessage());
           System.out.println ("SQLState:"+ex.getSQLState());
           System.out.println ("ErrorCode:"+ex.getErrorCode());
           ex=ex.getNextException();
      }
  }
  catch(Exception ex){
     ex.printStackTrace();
  }
  finally{
    try{
       if(statement!=null){
           statement.close();
       }
        if(connection!=null){
             connection.close();
        }
    }
     catch(SQLException ex){
              System.out.println("\nERROR:-------SQLException----------\n");
              System.out.println ("Message:"+ex.getMessage());
              System.out.println ("SQLState:"+ex.getSQLState());
              System.out.println ("ErrorCode:"+ex.getErrorCode());
     }
  }
%>
</body>
</html>
客户端页面程序是
<html>
<head><title>选择数据表名网页</title>
<meta http-equiv="Conten-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#ffffff" text"#000000">
<p align="center"><a href="dbJsp.jsp?tableName=studentbase">
                      学生地址表</a></p>
<p align="center"><a href="dbJsp.jsp?tableName=studentaddress">
                      学生基本信息表</a></p>
<p align="center"><a href="dbJsp.jsp?tableName=studentclass">
                      选课信息表</a></p>
</body>
</html>

可在编译dbJsp.jsp是出现错误
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
at org.apache.jsp.dbJsp$jsp._jspService(dbJsp$jsp.java:82)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
at java.lang.Thread.run(Thread.java:536)
哪个高手能帮帮我?????????????????????????????????????????????????????????????????????????????

回复列表 (共1个回复)

沙发

空函数的异常,肯定是你对一个没有值的变量进行操作了,自己找找吧

我来回复

您尚未登录,请登录后再回复。点此登录或注册