很简单啊,用对象前判断是否为空就可以啦if (rs != NULL) {
      if (rs.getInt("result") == 0) {
        result = "无法定位记录,记录更新前已被更改.";
      }
}

解决方案 »

  1.   

    这是错误提示。
    <2007-8-16 上午10时21分32秒> <Notice> <WebLogicServer> <000360> <Server started
    in RUNNING mode>
    java.lang.Exception: java.lang.ClassCastException
            at com.ParseXML.getConnection(Unknown Source)
            at com.ParseXML.createSQLStatement(Unknown Source)
            at promilestone.MsAppServerBean.updateBatch(MsAppServerBean.java:69)
            at promilestone.MsAppServerBean_nt0n1a_EOImpl.updateBatch(MsAppServerBea
    n_nt0n1a_EOImpl.java:3426)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.j
    ava:372)
            at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider
    .java:292)
            at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:
    276)
            at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrateg
    y.java:71)
            at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:156)
            at org.apache.axis.SimpleChain.invoke(SimpleChain.java:126)
            at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:437
    )
            at org.apache.axis.server.AxisServer.invoke(AxisServer.java:316)
            at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:70
    1)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
            at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBas
    e.java:335)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
            at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
    (ServletStubImpl.java:945)
            at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:332)
            at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:242)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
    n.run(WebAppServletContext.java:5363)
            at weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
    eManager.java:721)
            at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
    rvletContext.java:3043)
            at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
    pl.java:2466)
            at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:152)
            at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:133)
    Caused by: java.lang.ClassCastException
            ... 29 more
    java.lang.NullPointerException
            at promilestone.MsAppServerBean.updateBatch(MsAppServerBean.java:90)
            at promilestone.MsAppServerBean_nt0n1a_EOImpl.updateBatch(MsAppServerBea
    n_nt0n1a_EOImpl.java:3426)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.j
    ava:372)
            at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider
    .java:292)
            at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:
    276)
            at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrateg
    y.java:71)
            at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:156)
            at org.apache.axis.SimpleChain.invoke(SimpleChain.java:126)
            at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:437
    )
            at org.apache.axis.server.AxisServer.invoke(AxisServer.java:316)
            at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:70
    1)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
            at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBas
    e.java:335)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
            at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
    (ServletStubImpl.java:945)
            at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:332)
            at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:242)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
    n.run(WebAppServletContext.java:5363)
            at weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
    eManager.java:721)
            at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
    rvletContext.java:3043)
            at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
    pl.java:2466)
            at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:152)
            at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:133)
      

  2.   

    其中getConnection的类
    public class ConnectServer {
      public static String mainDataSoure = "MsTxDSSQLServer";  public ConnectServer() {
      }  public java.sql.Connection getConnection() {
        InitialContext initCtx = null;
        try {
          initCtx = new InitialContext();
          DataSource ds = (javax.sql.DataSource) initCtx.lookup(mainDataSoure);
          return ds.getConnection();
        }
        catch (Exception ne) {
          throw new EJBException(ne);
        }
        finally {
          try {
            if (initCtx != null) {
              initCtx.close();
            }
          }
          catch (NamingException ne) {
            throw new EJBException(ne);
          }
        }
      }  public java.sql.Connection getConnection(String dataSource) {
        String txdataSource = dataSource;
        if (txdataSource.equals("")) {
          txdataSource = mainDataSoure;
        }
        InitialContext initCtx = null;
        try {
          initCtx = new InitialContext();
          DataSource ds = (javax.sql.DataSource) initCtx.lookup(txdataSource);
          return ds.getConnection();
        }
        catch (Exception ne) {
          throw new EJBException(ne);
        }
        finally {
          try {
            if (initCtx != null) {
              initCtx.close();
            }
          }
          catch (NamingException ne) {
            throw new EJBException(ne);
          }
        }
      }  public java.sql.Connection getConnection(int dataSource) {
        java.sql.Connection con = getConnection();    InitialContext initCtx = null;
        try {
          initCtx = new InitialContext();
          DataSource ds = (javax.sql.DataSource) initCtx.lookup(mainDataSoure);
          return ds.getConnection();
        }
        catch (Exception ne) {
          throw new EJBException(ne);
        }
        finally {
          try {
            if (initCtx != null) {
              initCtx.close();
            }
          }
          catch (NamingException ne) {
            throw new EJBException(ne);
          }
        }
      }  public void cleanup(Connection con, PreparedStatement ps) {
        try {
          if (ps != null) {
            ps.close();
          }
        }
        catch (Exception e) {
          e.printStackTrace();
        }
        //将数据库联接返回缓冲池
        try {
          if (con != null) {
            con.close();
          }
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }