SimpleDateFormat问题:java.lang.NumberFormatException: For input string: ""

shjie5246 2008-04-30 03:20:01
private static SSCLotteryInfo GetInfo(ResultSet rs) {
if (rs == null) {
return null;
}
try {
String SSC_QH = rs.getString("SSC_QH");
String SSC_KJSJ = rs.getString("SSC_KJSJ");
String SSC_KJHM = rs.getString("SSC_KJHM");
byte IS_TKS = rs.getByte("IS_TKS");
byte IS_YKJ = rs.getByte("IS_YKJ");
Date startTime = format.parse(SSC_KJSJ.trim());
SSCLotteryInfo sscinfo = new SSCLotteryInfo(SSC_QH, startTime,
SSC_KJHM, IS_TKS, IS_YKJ);
return sscinfo;
} catch (Exception ex) {
ex.printStackTrace();
Log.getLogger().info(ex);
return null;
}
}




public static SSCLotteryInfo GetLotteryInfo() {
SSCLotteryInfo sscinfo = null;
Connection con = DBCPManager.getInstance().getConnection();
if (con == null) {
return null;
}
synchronized (con) {
String sql = "select * from SSC_Lottery where SSC_KJSJ >'" +
format.format(new Date(new Date().getTime() + 1000)) + "'";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next()) {
sscinfo = GetInfo(rs);
}
} catch (Exception ex) {
ex.printStackTrace();
Log.getLogger().info(ex);
} finally {
ExecuteSQL.closeAll(rs, pstmt, con);
}
}
return sscinfo;
}

为什么有时会报这样的错误:java.lang.NumberFormatException: For input string: ""
...全文
1018 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
Shine_Panda 2008-04-30
  • 打赏
  • 举报
回复
同意ls
java.lang.NumberFormatException: For input string: ""
说名你在 转换数据的时候将一个 "" 转成一个 int 型的时候出错了.
xtzhoujie 2008-04-30
  • 打赏
  • 举报
回复
我想是楼主发错代码了吧.
java.lang.NumberFormatException 异常是解析数字型字符串才报的错.
SimpleDateFormat.parse(string) 是报ParseException
其余的是SQLException
而SimpleDateFormat.format(String) 异常是java.lang.IllegalArgumentException
lever0066 2008-04-30
  • 打赏
  • 举报
回复
这样写
   
public static String getDateTimeNow() {

SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
java.util.Date now = new java.util.Date();

return df.format(now);
}
hx2044 2008-04-30
  • 打赏
  • 举报
回复
Date startTime = format.parse(SSC_KJSJ.trim());
里头内容为空
songfuqiang 2008-04-30
  • 打赏
  • 举报
回复
SimpleDateFormat simp=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Sysem.err.println(simp.format(new Date());
shjie5246 2008-04-30
  • 打赏
  • 举报
回复
数据库中是有值的
shjie5246 2008-04-30
  • 打赏
  • 举报
回复 1
检测过了,检测不出来.
这个错误是不定时出现的.不知道为什么.
小南瓜瓜 2008-04-30
  • 打赏
  • 举报
回复
这种问题经常会碰到就是因为使用的时候参数为""
楼主检查一下报错的是哪行
shjie5246 2008-04-30
  • 打赏
  • 举报
回复
检测了,哪行都没报错
log日志打印是报这样的错误的
我定义的时间格式为:
public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
shjie5246 2008-04-30
  • 打赏
  • 举报
回复
检测了,哪行都没报错

log日志里打印是报这样的错误的

时间格式是这样的
public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
小南瓜瓜 2008-04-30
  • 打赏
  • 举报
回复
我猜是在这里
Date startTime = format.parse(SSC_KJSJ.trim());
SSC_KJSJ=""
dracularking 2008-04-30
  • 打赏
  • 举报
回复
提示很明显了 String转换到数字类型时格式不合适才报的异常
应该会有定位 找找吧
小南瓜瓜 2008-04-30
  • 打赏
  • 举报
回复
是因为你在用到SimpleDateFormat的地方输入的参数是""
检查一下 为什么是""吧
jastby 2008-04-30
  • 打赏
  • 举报
回复
哪行报错?

格式不符合 需要转换的格式

81,091

社区成员

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

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