这个文件是我反编译过的,没有经过修改,重新编译时为什么总提示:      exception;有错误??
package operate_db;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import sun.jdbc.rowset.CachedRowSet;
public class OperateDb
{
    protected String query_statement;
    protected String param[];
    protected Connection conn;
    protected String jndiname;
    private String conTime;
    private boolean isConnected;
    public static int conCount = 0;
    public OperateDb()
    {
        query_statement = "";
        conn = null;
        isConnected = false;
    }
    protected void setParam(String as[])
    {
        param = as;
    }
    private void setQuerystatement(String s)
    {
        query_statement = s;
    }
    public Connection getConn()
    {
        return conn;
    }
    public void dbConn()
        throws Exception
    {
        if(isConnected)
            return;
        Object obj = null;
        DataSource datasource = null;
        if(conCount % 100 == 0)
            System.out.println(conCount + "," + Runtime.getRuntime().totalMemory());
        try
        {
            InitialContext initialcontext = new InitialContext();
            if(initialcontext == null)
                throw new Exception(" Context not Find");
            if(datasource == null)
                datasource = (DataSource)initialcontext.lookup(jndiname);
            if(datasource != null)
            {
                Connection connection = datasource.getConnection();
                if(connection == null)
                    throw new Exception(jndiname + " connecte fail! ");
                isConnected = true;
                conn = connection;
                conCount++;
                initialcontext.close();
            }
        }
        catch(Exception exception)
        {
            System.out.println(exception.getMessage());
            throw new Exception(toString() + " error DataBase " + jndiname + " Connect Fail,Please Wait For 5 Minutes!");
        }
    }
    public void dbClose()
        throws Exception
    {
        if(conn != null && isConnected && !conn.isClosed())
        {
            isConnected = false;
            conn.close();
        }
    }
    protected ResultSet getResult()
    {
        ResultSet resultset = null;
        try
        {
            PreparedStatement preparedstatement = conn.prepareStatement(query_statement, 1004, 1007);
            if(param != null)
            {
                for(int i = 0; i < param.length; i++)
                    preparedstatement.setString(i + 1, param[i]);
            }
            resultset = preparedstatement.executeQuery();
        }
        catch(Exception exception)
        {
            System.out.println(exception);
        }
        return resultset;
    }
    private int updateRecordDb()
        throws SQLException, UnsupportedEncodingException
    {
        dbConn();
        if(!isConnected)
            throw new Exception(jndiname + " not connected");
        PreparedStatement preparedstatement = conn.prepareStatement(query_statement);
        if(param != null)
        {
            for(int i = 0; i < param.length; i++)
                preparedstatement.setString(i + 1, param[i]);
        }
        preparedstatement.executeUpdate();
        preparedstatement.close();
        conn.commit();
        dbClose();
        return 1;
        Exception exception;
        exception;
        System.out.println("updateRecordDb failed:\r\n" + query_statement + " " + exception);
        conn.rollback();
        return -1;
    }
    private int updateRecord()
        throws SQLException, UnsupportedEncodingException
    {
        PreparedStatement preparedstatement = conn.prepareStatement(query_statement);
        if(param != null)
        {
            for(int i = 0; i < param.length; i++)
                preparedstatement.setString(i + 1, param[i]);
        }
        preparedstatement.executeUpdate();
        preparedstatement.close();
        conn.commit();
        return 1;
        Exception exception;
        exception;
        System.out.println(exception);
        conn.rollback();
        return -1;
    }
    public boolean isHaveField(String s, String s1, String s2)
    {
        query_statement = "select count(*) as countnum from " + s + " where " + s1 + "='" + s2 + "'";
        Object obj = null;
        int i;
        if(!isConnected)
            throw new Exception(jndiname + " not connected");
        setQuerystatement(query_statement);
        ResultSet resultset = getResult();
        resultset.next();
        i = resultset.getInt(1);
        resultset.close();
        if(i > 0)
            return true;
        return false;
        Exception exception;
        exception;
        System.out.println(exception);
        return true;
    }
    public boolean isHaveField(String s, String s1, long l)
    {
        query_statement = "select count(*) as countnum from " + s + " where " + s1 + "=" + l;
        Object obj = null;
        int i;
        dbConn();
        if(!isConnected)
            throw new Exception(jndiname + " not connected");
        setQuerystatement(query_statement);
        ResultSet resultset = getResult();
        resultset.next();
        i = resultset.getInt(1);
        resultset.close();
        dbClose();
        if(i > 0)
            return true;
        return false;
        Exception exception;
        exception;
        System.out.println(exception);
        return true;
    }
    public ResultSet getResult(String s)
    {
        ResultSet resultset = null;
        try
        {
            if(!isConnected)
                dbConn();
            if(!isConnected)
                throw new Exception(jndiname + " not connected");
            setQuerystatement(s);
            resultset = getResult();
        }
        catch(Exception exception)
        {
            System.out.println("getResult: " + s + ":  " + exception);
        }
        return resultset;
    }
    public int exeCute(String s)
    {
        if(!isConnected)
            throw new Exception(jndiname + " not connected");
        setQuerystatement(s);
        return updateRecord();
        Exception exception;
        exception;
        System.out.println("exeCute1: " + s + ":  " + exception);
        return -1;
    }
    public int exeSql(String s)
    {
        setQuerystatement(s);
        return updateRecordDb();
        Exception exception;
        exception;
        System.out.println("exeSql: " + s + ":  " + exception);
        System.out.println(exception);
        return -1;
    }
    public CachedRowSet getRowSet(String s)
    {
        CachedRowSet cachedrowset = null;
        setQuerystatement(s);
        try
        {
            dbConn();
            if(!isConnected)
                throw new Exception(jndiname + " not connected");
            PreparedStatement preparedstatement = conn.prepareStatement(query_statement, 1004, 1008);
            if(param != null)
            {
                for(int i = 0; i < param.length; i++)
                    preparedstatement.setString(i + 1, param[i]);
            }
            ResultSet resultset = preparedstatement.executeQuery();
            cachedrowset = new CachedRowSet();
            cachedrowset.populate(resultset);
            preparedstatement.close();
            resultset.close();
            dbClose();
        }
        catch(SQLException sqlexception)
        {
            System.out.println("Error occurs in queryRowSet");
            cachedrowset = null;
        }
        catch(Exception exception)
        {
            System.out.println(exception.getMessage());
            cachedrowset = null;
        }
        finally
        {
            return cachedrowset;
        }
        do
            ;
        while(true);
    }
    public String computeDouble(String s, String s1, String s2)
    {
        String s3;
        String s4;
        s3 = "0";
        if(s == null)
            s = "";
        if("".equals(s))
            s = "0";
        if(s1 == null)
            s1 = "";
        if("".equals(s1))
            s1 = "0";
        s4 = "select " + s + s2 + s1 + " as rtn";
        ResultSet resultset = getResult(s4);
        if(resultset.next())
        {
            s3 = resultset.getString("rtn");
            if(s3 == null)
                s3 = "0";
        }
        resultset.close();
        return s3;
        Exception exception;
        exception;
        System.out.println(exception);
        return "0";
    }
}
[此贴子已经被作者于2006-8-21 18:46:43编辑过]

 
											





 PiepK1yk.rar
PiepK1yk.rar 
	    

