求救:覆盖ResultSet的getFloat()方法!

煜知搬砖者 2003-01-24 03:04:06
当字段内容为null时,ResultSet的getFloat方法得到的值是0.0
请问我想这样:当字段内容为null时,得到-1.00,
请问大家有和建议?
...全文
101 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
kaolaxiong 2003-01-24
  • 打赏
  • 举报
回复
try{}catch(Exception ex){

}
ChDw 2003-01-24
  • 打赏
  • 举报
回复
那赶快给分我!!! :)
煜知搬砖者 2003-01-24
  • 打赏
  • 举报
回复
问题得到解决。 ChDw(米)的方法是正确的。
谢谢。
ChDw 2003-01-24
  • 打赏
  • 举报
回复
自己继承ResultSet是不可行的,因为
ResultSet rs = ....
实际上rs并不是ResultSet的这个类,它仅仅是一个实现了这个接口的类
根据不同的数据库厂商实际是不同的,就是说
ResultSet rs = ...;
System.out.println("Class:" + rs.getClass().getName());
你这样就可以看到实际上rs的类是什么了
bdsc 2003-01-24
  • 打赏
  • 举报
回复
class abc extends ResultSet 对么?!

ChDw(米)
是最可行的
float a = rs.getFloat(1);
if(rs.wasNull())
a = -1.0
caoze 2003-01-24
  • 打赏
  • 举报
回复

float a = ( rs.getFloat("af") == 0.0? -1.0 : rs.getFloat("af") );
ChDw 2003-01-24
  • 打赏
  • 举报
回复
float a = rs.getFloat(1);
if(rs.wasNull())
a = -1.0
煜知搬砖者 2003-01-24
  • 打赏
  • 举报
回复
to: jinmin(★猪猪★)
有没有实现的源代码?
煜知搬砖者 2003-01-24
  • 打赏
  • 举报
回复
还有一个问题比较关键,要是字段本身的值是0的话,那怎么办呢?
danceflash 2003-01-24
  • 打赏
  • 举报
回复
恩~~~

study_body(珍惜每一天)的方法不错

学习、学习~~~^_^
study_body 2003-01-24
  • 打赏
  • 举报
回复
class abc extends ResultSet
{
float getFloat(int i)
{
if(super.getFloat(i))=0 return -1;
else return super.getFloat(i);
}
}

思路就是这样,具体实现再自己看看
study_body 2003-01-24
  • 打赏
  • 举报
回复
抱歉,应该是
class abc extends ResultSet
{
float getFloat()
{
if(super.getFloat())=0 return -1;
else return super.getFloat();
}
}
baihuazhang 2003-01-24
  • 打赏
  • 举报
回复
提个不知道对不对的建议啊,可以设置一个变量a=rs.getFloat();
if (a==0.0)
a=-1.0;
请各位大虾指教
study_body 2003-01-24
  • 打赏
  • 举报
回复
class abc extends ResultSet
{
void getFloat()
{
if(super.getFloat())=0 return -1;
else return super.getFloat();
}
}
jinmin 2003-01-24
  • 打赏
  • 举报
回复
可以参考:
// 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.java

package java.sql;

import java.io.InputStream;
import java.math.BigDecimal;

// Referenced classes of package java.sql:
// SQLException, Date, Time, Timestamp,
// SQLWarning, ResultSetMetaData

public 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;
}
danceflash 2003-01-24
  • 打赏
  • 举报
回复
可以先看看ResultSet的getFloat()方法的源代码
煜知搬砖者 2003-01-24
  • 打赏
  • 举报
回复
请大家给点思路,谢谢了。
煜知搬砖者 2003-01-24
  • 打赏
  • 举报
回复
关键是怎么写那个方法阿,呵呵
study_body 2003-01-24
  • 打赏
  • 举报
回复
自己建立一个对象,可以从ResultSet中继承,然后覆盖该方法

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧