con 为null;
不妨先判断一下。

解决方案 »

  1.   

    我的con确实为null,我想用连接池技术,但是好象没有配置正确,我在server.xml文件中加了以下内容:(其他的没有作什么改变)<Context path="/jspFile" docBase="jspFile" debug="0" reloadable="true">

    <Resource name="jdbc/jspFile" auth="Container" type="javax.sql.DataSource" />
      <ResourceParams name="jdbc/jspFile">
      <parameter><name>factory</name>
    <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
    </parameter>
    <parameter><name>driverClassName</name>
    <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
    </parameter>
     <parameter><name>url</name>
    <value>jdbc:microsoft:sqlserver://JNSDSVR-4:1433;DataBaseName=pubs</value>
    </parameter>
    <parameter><name>username</name><value>sa</value></parameter>
    <parameter><name>password</name><value>sa</value></parameter>
     <parameter><name>maxActive</name><value>20</value></parameter>
     <parameter><name>maxIdle</name><value>10</value></parameter>
      <parameter><name>maxWait</name><value>-1</value></parameter>
      </ResourceParams>
    </Context>jspFile是我在webapps文件夹下新加的一个文件夹!
    还有一个提示错误是:could not create resource factory。
    到底是哪里的错误呢?
      

  2.   

    你好像是连的sqlserver数据库的jdbc驱动,你的数据库开了吗?你的地址对吗?
    你的数据库密码是sa 吗?我没连过sqlserver,你写的对不对说不上来.
    java.lang.NullPointerException 是一个连接不上数据库的提示!!!看看吧,不一定对不过你要是对了,把INI写出来我学习一下
      

  3.   

    could not create resource factory。这个错误提示连接池的配置根本没有在server.xml读到,最好在应用服务器:tomcat,weblogic 的管理界面上先配置好连接池,然后写从连接池中实例化连接的语句
      

  4.   

    // Locate the naming initial context
    javax.naming.InitialContext ctx = new javax.naming.InitialContext();/* perform a JNDI lookup for the DataSource. The JNDI name in the code is a resource reference and is not necessary the same as the JNDI name you defined for the DataSource. You need to bind this resource reference to the real JNDI name in the deployment descriptor. Please follow the installation instruction. */javax.sql.DataSource myDS =
    (javax.sql.DataSource) ctx.lookup("java:comp/env/jdbc/MyDS");// create a connection from the DataSource
    connection = myDS.getConnection();// create a query from the connection
    java.sql.Statement query = connection.createStatement();/* create the result set. You probably need to add the qualifier  to the table name in the SQL statement */
    rs = query.executeQuery("SELECT * FROM DEPARTMENT");