首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

java.lang.NumberFormatException: For input string异常

2014-01-26 
private static SSCLotteryInfo GetInfo(ResultSet rs) { if (rs null) { return null } try { String

  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: ""

------解决方法--------------------------------------------------------
哪行报错?

格式不符合 需要转换的格式
------解决方法--------------------------------------------------------
是因为你在用到SimpleDateFormat的地方输入的参数是""
检查一下 为什么是""吧
------解决方法--------------------------------------------------------
提示很明显了 String转换到数字类型时格式不合适才报的异常
应该会有定位 找找吧
------解决方法--------------------------------------------------------
我猜是在这里
Date startTime = format.parse(SSC_KJSJ.trim());
SSC_KJSJ=""

------解决方法--------------------------------------------------------
SimpleDateFormat simp=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Sysem.err.println(simp.format(new Date());
------解决方法--------------------------------------------------------
  Date startTime = format.parse(SSC_KJSJ.trim());
里头内容为空
------解决方法--------------------------------------------------------
我想是你发错代码了吧.
java.lang.NumberFormatException 异常是解析数字型字符串才报的错.
SimpleDateFormat.parse(string) 是报ParseException
其余的是SQLException
而SimpleDateFormat.format(String) 异常是java.lang.IllegalArgumentException

        

热点排行