自己建立一个对象,可以从ResultSet中继承,然后覆盖该方法

解决方案 »

  1.   

    可以先看看ResultSet的getFloat()方法的源代码
      

  2.   

    可以参考:
    // Decompiled by Jad v1.5.7. Copyright 1997-99 Pavel Kouznetsov.
    // Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
    // Decompiler options: packimports(3) 
    // Source File Name:   ResultSet.javapackage java.sql;import java.io.InputStream;
    import java.math.BigDecimal;// Referenced classes of package java.sql:
    //            SQLException, Date, Time, Timestamp, 
    //            SQLWarning, ResultSetMetaDatapublic interface ResultSet
    {    public abstract boolean next()
            throws SQLException;    public abstract void close()
            throws SQLException;    public abstract boolean wasNull()
            throws SQLException;    public abstract String getString(int i)
            throws SQLException;    public abstract boolean getBoolean(int i)
            throws SQLException;    public abstract byte getByte(int i)
            throws SQLException;    public abstract short getShort(int i)
            throws SQLException;    public abstract int getInt(int i)
            throws SQLException;    public abstract long getLong(int i)
            throws SQLException;    public abstract float getFloat(int i)
            throws SQLException;    public abstract double getDouble(int i)
            throws SQLException;    public abstract BigDecimal getBigDecimal(int i, int j)
            throws SQLException;    public abstract byte[] getBytes(int i)
            throws SQLException;    public abstract Date getDate(int i)
            throws SQLException;    public abstract Time getTime(int i)
            throws SQLException;    public abstract Timestamp getTimestamp(int i)
            throws SQLException;    public abstract InputStream getAsciiStream(int i)
            throws SQLException;    public abstract InputStream getUnicodeStream(int i)
            throws SQLException;    public abstract InputStream getBinaryStream(int i)
            throws SQLException;    public abstract String getString(String s)
            throws SQLException;    public abstract boolean getBoolean(String s)
            throws SQLException;    public abstract byte getByte(String s)
            throws SQLException;    public abstract short getShort(String s)
            throws SQLException;    public abstract int getInt(String s)
            throws SQLException;    public abstract long getLong(String s)
            throws SQLException;    public abstract float getFloat(String s)
            throws SQLException;    public abstract double getDouble(String s)
            throws SQLException;    public abstract BigDecimal getBigDecimal(String s, int i)
            throws SQLException;    public abstract byte[] getBytes(String s)
            throws SQLException;    public abstract Date getDate(String s)
            throws SQLException;    public abstract Time getTime(String s)
            throws SQLException;    public abstract Timestamp getTimestamp(String s)
            throws SQLException;    public abstract InputStream getAsciiStream(String s)
            throws SQLException;    public abstract InputStream getUnicodeStream(String s)
            throws SQLException;    public abstract InputStream getBinaryStream(String s)
            throws SQLException;    public abstract SQLWarning getWarnings()
            throws SQLException;    public abstract void clearWarnings()
            throws SQLException;    public abstract String getCursorName()
            throws SQLException;    public abstract ResultSetMetaData getMetaData()
            throws SQLException;    public abstract Object getObject(int i)
            throws SQLException;    public abstract Object getObject(String s)
            throws SQLException;    public abstract int findColumn(String s)
            throws SQLException;
    }
      

  3.   

    class abc extends ResultSet
    {
       void getFloat()
       {
           if(super.getFloat())=0 return -1;
            else return super.getFloat();
       }
    }
      

  4.   

    提个不知道对不对的建议啊,可以设置一个变量a=rs.getFloat();
    if (a==0.0)
       a=-1.0;
    请各位大虾指教
      

  5.   

    抱歉,应该是
    class abc extends ResultSet
    {
       float getFloat()
       {
           if(super.getFloat())=0 return -1;
            else return super.getFloat();
       }
    }
      

  6.   

    class abc extends ResultSet
    {
       float getFloat(int i)
       {
           if(super.getFloat(i))=0 return -1;
            else return super.getFloat(i);
       }
    }思路就是这样,具体实现再自己看看
      

  7.   

    恩~~~study_body(珍惜每一天)的方法不错学习、学习~~~^_^
      

  8.   

    to: jinmin(★猪猪★) 
    有没有实现的源代码?
      

  9.   

    float a = rs.getFloat(1);
    if(rs.wasNull()) 
      a = -1.0
      

  10.   


    float a = ( rs.getFloat("af") == 0.0? -1.0 : rs.getFloat("af") );
      

  11.   

    class abc extends ResultSet 对么?!ChDw(米)
    是最可行的
    float a = rs.getFloat(1);
    if(rs.wasNull()) 
      a = -1.0
      

  12.   

    自己继承ResultSet是不可行的,因为
    ResultSet rs = ....
    实际上rs并不是ResultSet的这个类,它仅仅是一个实现了这个接口的类
    根据不同的数据库厂商实际是不同的,就是说
    ResultSet rs = ...;
    System.out.println("Class:" + rs.getClass().getName());
    你这样就可以看到实际上rs的类是什么了
      

  13.   

    问题得到解决。 ChDw(米)的方法是正确的。
    谢谢。