社区
Java SE
帖子详情
求救:覆盖ResultSet的getFloat()方法!
煜知搬砖者
2003-01-24 03:04:06
当字段内容为null时,ResultSet的getFloat方法得到的值是0.0
请问我想这样:当字段内容为null时,得到-1.00,
请问大家有和建议?
...全文
101
19
打赏
收藏
求救:覆盖ResultSet的getFloat()方法!
当字段内容为null时,ResultSet的getFloat方法得到的值是0.0 请问我想这样:当字段内容为null时,得到-1.00, 请问大家有和建议?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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中继承,然后覆盖该方法
JAVA中JDBC极简实操入门
queryByid、Statement接口的应用-delete测试、Statement接口的应用-新增测试、
ResultSet
的应用-1-项目环境搭建、
ResultSet
的应用-2-查询数据、
ResultSet
的应用-3-优化代码、
ResultSet
的应用-4-定义实体类、
ResultSet
...
ResultSet
is closed!
这是本人在CSDN BLOG发表的第一篇文章,哈哈,我... 昨晚搞了足足一个晚上,用了N种
方法
还是不行,最后实验了N遍,发现
ResultSet
有个很特殊的地方,那就是当从Statement得到一个
ResultSet
_1后,必须要先操作
ResultSet
_
java.sql.SQLException: Exhausted
Resultset
原因分析
出现这个错误的原因是因为
ResultSet
curser 指针已经在最后一个元素之外了,说明要么是
ResultSet
集合为空 ,要么是 集合已经没有可以读取的元素了 ,此时你再调用rs.get()获取元素,就会报错。 if (rs! = null)...
Oracle数据库,结果集已关闭(SQLException: Closed
Resultset
)
在制作BBS论坛的过程中,根据需要,我计划将数据库的访问、查询操作和查询结果分在两个...private
ResultSet
executeQuery(String sql) throws SQLException { try{ conn=ds.getConnection(); conn.setAutoCo
java.sql.SQLException:
ResultSet
is closed
自定义连接池将mysql和spark-streaming进行集成,连接池JDBCWrapper类中的doQuery()
方法
如下:public
ResultSet
doQuery(String sqlText) { Connection conn = getConnection(); PreparedStatement ...
Java SE
62,615
社区成员
307,307
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章