package com.philwong.util;import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;public class Utility {    public static void close(Connection conn){
        try
        {
         conn.close();
        }
        catch (Exception e)
        {
            System.err.println("ERROR:exception close Connection");
            System.err.println("¡Á¡Á¡Á¡Á¡Á¹Ø±ÕÊý¾Ý¿âÁ¬½Óʱ³öÏÖÒì³£¡Á¡Á¡Á¡Á¡Á");
            System.err.println(e);
        }
    }
}驱动用的是jdbc-odbc桥:
private static final String DBDRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
private static final String DBURL = "jdbc:odbc:ddecerp";    private ConnectionFactory(){
        try
        {
         Class.forName(DBDRIVER);
        }
        catch (ClassNotFoundException e)
        {
            System.err.println("ERROR:exception loading driver class");
            System.err.println("¡Á¡Á¡Á¡Á¡ÁδÕÒµ½Çý¶¯³ÌÐòÀà¡Á¡Á¡Á¡Á¡Á");
        }
    }    public static Connection getConnection() throws SQLException{
        return DriverManager.getConnection(DBURL,USER,PW);
    }

解决方案 »

  1.   

    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null,rs2 = null;
    String sql = "";
    CachedRowSet cachedRs = new CachedRowSet();
    try
    {
        conn = ConnectionFactory.getConnection();
        stmt = conn.createStatement();
        //sql = "select * from TSC_DayReport1 where convert(char(10),RQ,120)='" + date + "'";
        sql = "select isnull(dh,' ') as dh,isnull(jh,' ') as jh,isnull(kzrq,' ') as kzrq,isnull(jb,' ') as jb,isnull(sjjs,' ') as sjjs,isnull(sjjs1,' ') as sjjs1,isnull(mdi,' ') as mdi,isnull(zd,' ') as zd,isnull(jc,' ') as jc,isnull(yjh,' ') as yjh,isnull(tgcx,' ') as tgcx,isnull(ztxhcc,' ') as ztxhcc,isnull(zt,' ') as zt,isnull(ztpz,' ') as ztpz,isnull(zy,' ') as zy,isnull(zs,' ') as zs,isnull(gj,' ') as gj,isnull(bya,' ') as bya,isnull(md,' ') as md,isnull(nd,' ') as nd,isnull(ss,' ') as ss,isnull(hs,' ') as hs,isnull(cq,' ') as cq,isnull(zq,' ') as zq,isnull(ph,' ') as ph,isnull(gbld,' ') as gbld,isnull(dt,' ') as dt,isnull(gznr,' ') as gznr,isnull(srr,' ') as srr,isnull(shr,' ') as shr,isnull(jx,' ') as jx,isnull(jcylj,' ') as jcylj,isnull(jcnlj,' ') as jcnlj from tsc_dayreport1 where (convert(char(10), rq, 120) = '" + date + "') order by jh";
        //rs = stmt.executeQuery(sql);
        cachedRs.setCommand(sql);
        cachedRs.execute(conn);
        sql = "select * from TSC_DayReportunion1 where convert(char(10),RQ,120)='" + date + "' order by jlx desc";
        rs2 = stmt.executeQuery(sql);
    }
    catch (Exception e)
    {
        System.err.println(e);
    }
    //此处省略若干无关代码,方便兄弟们阅读。
    //Utility.close(rs);
    Utility.close(rs2);
    Utility.close(stmt);
    Utility.close(conn);
    就是在最后一句报错了。
      

  2.   

    CachedRowSet类是sun公司的一个类,我没有源码。