class="DBconn.DBconn“
这里的路径对吗?

解决方案 »

  1.   

    对的呀,放在WEB-INF 的CLASSES 下的,DBconn下
      

  2.   

    你是用odbc?? 那你的odbc 配置了没有??
      

  3.   

    不知道,你的bean中的包写了没有啊。package DBconn;
    别的没看出来什么问题,你也可以把查询语句写在bean
    中,然后写个输出语句看下System.out.println();
      

  4.   

    用了包
    odbc也配制了
    在学校机房上的机子上我配制了可以运行
    在我的机子就没有配制出来,
    不过我很多同学也出现了一样的错误
      

  5.   

    package DBconn;
    import java.sql.*;
    /**
     * @author Administrator
     *
     * To change this generated comment edit the template variable "typecomment":
     * Window>Preferences>Java>Templates.
     * To enable and disable the creation of type comments go to
     * Window>Preferences>Java>Code Generation.
     */
    public class DBconn { String strDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String strConn = "jdbc:odbc:flower";
    Connection connect = null;
    ResultSet rs = null;
    Statement stmt=null;

    public DBconn() {
    try {
    Class.forName(strDBDriver);
    } catch(java.lang.ClassNotFoundException e) {
    System.err.print(e.getMessage());
    }
    }

    public ResultSet executeQuery (String sql) {
    try {
    connect = DriverManager.getConnection(strConn);
     stmt = connect.createStatement();
    rs = stmt.executeQuery(sql);
    } catch (SQLException ex) {
    System.err.println(ex.getMessage());
    }
    return rs;
    }    }
    后台的错误是:
    java.lang.NullPointerException
    org.apache.jsp.DBconn_jsp._jspService(DBconn_jsp.java:85)
    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)
      

  6.   

    问题可能很多,不好说你先单独测一下bean是否可以连数据库
      

  7.   

    连不上,由executeQuery (String sql)返回的是空值
    这是怎么回事?
      

  8.   

    可能性:
    1、你的类放在class 目录下了吗?
    2、WEB-INF目录下的web.xml文件为:<?xml version="1.0" encoding="ISO-8859-1"?>
    <!--
      Copyright 2004 The Apache Software Foundation  Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    --><web-app xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        version="2.4">  <display-name>Welcome to Tomcat</display-name>
      <description>
         Welcome to Tomcat
      </description>
    <!-- JSPC servlet mappings start -->    <servlet>
            <servlet-name>org.apache.jsp.index_jsp</servlet-name>
            <servlet-class>org.apache.jsp.index_jsp</servlet-class>
        </servlet>    <servlet-mapping>
            <servlet-name>org.apache.jsp.index_jsp</servlet-name>
            <url-pattern>/index.jsp</url-pattern>
        </servlet-mapping><!-- JSPC servlet mappings end --></web-app>