java.rmi.ServerException: RuntimeException; nested exception is:
java.lang.NumberFormatException: For input string: "09 09:34:09"
org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:421)
出现的这样的异常:请各位帮忙分析下,或给我提示:谢谢public int addMessage(int send_id, int recieve_id, String topic, String message) {//发送留言 JSP调用
// TODO Auto-generated method stub
SimpleDateFormat formatter=
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String mydate=formatter.format(Calendar.getInstance().getTime());
java.sql.Date sqlDate=java.sql.Date.valueOf(mydate);
try {
PreparedStatement pstmt2 = sqlConn
.prepareStatement("insert into member_msg(send_id,recieve_id,readtimes,topic,sendtime,message) values(?,?,?,?,?,?)"); pstmt2.setInt(1,send_id);
pstmt2.setInt(2, recieve_id);
pstmt2.setInt(3, 0);
pstmt2.setString(4, topic);
pstmt2.setDate(5, sqlDate);
pstmt2.setString(6, message);
pstmt2.executeUpdate();
pstmt2.close();
return 1;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
这里的日期获取之后 在添加到数据库就出现了问题。数据库是 sql server!
java.lang.NumberFormatException: For input string: "09 09:34:09"
org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:421)
出现的这样的异常:请各位帮忙分析下,或给我提示:谢谢public int addMessage(int send_id, int recieve_id, String topic, String message) {//发送留言 JSP调用
// TODO Auto-generated method stub
SimpleDateFormat formatter=
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String mydate=formatter.format(Calendar.getInstance().getTime());
java.sql.Date sqlDate=java.sql.Date.valueOf(mydate);
try {
PreparedStatement pstmt2 = sqlConn
.prepareStatement("insert into member_msg(send_id,recieve_id,readtimes,topic,sendtime,message) values(?,?,?,?,?,?)"); pstmt2.setInt(1,send_id);
pstmt2.setInt(2, recieve_id);
pstmt2.setInt(3, 0);
pstmt2.setString(4, topic);
pstmt2.setDate(5, sqlDate);
pstmt2.setString(6, message);
pstmt2.executeUpdate();
pstmt2.close();
return 1;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
这里的日期获取之后 在添加到数据库就出现了问题。数据库是 sql server!
解决方案 »
- 坐等求解! myeclipse文本输出截断and某些字符的乱码问题
- 如何将当前页面的值赋给java变量
- 如何取hidden值
- 关于数据加密的问题???
- com.utils.CounterListener是什么类
- 关于web.xml的问题
- 在struts-config.xml中,我想配置一个变量,然后由javabean读取,该如何配置,javabean又该如何读取呢
- 请教一个javascript的radiobutton的问题!100分!近来就有!
- 连接池如果设定最大连接数为5,那么数据库中它的进程是否最大只可以有5个?
- 在jsp中,如何在jsp页面中显示.exe文件?谢谢!!
- 一个struts程序运行的流程问题!
- 怎样将下载的源代码(明日科技《JSP数据库编程》)中使用的mysql数据库改成使用sql server?
java.sql.date 还是不行,就出现了这样的错误! 都不知道怎么办才好,没了头绪啊,请高手帮忙下,指点一二!谢谢。
2.建议你把 你把数据库里存日期的改成varchar(20),这样存取都方便很多
smalldatetime 只能精确到分钟
smalldatetime 只能精确到分钟
datetime的有效时间范围:1753/1/1~9999/12/31
<二> smalldatetime只精确到分,而datetime而datatime可以精确到3%秒(3.33毫秒)。
smalldatetime占用4个字节,前2个字节存储base date(1900年1月1日)之后的天数。后2个字节存储午夜后的分钟数。
datetime占用8个字节,前4个字节存储base date(即1900年1月1日)之前或之后的天数,后4个字节存储午夜后的毫秒数。
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String mydate=formatter.format(Calendar.getInstance().getTime()); 转换出错了!
你应该把你得到的事件先打印 看看是什么结构的然后在转换
java.sql.Date sqlDate=java.sql.Date.valueOf(mydate);
你这里的mydate是yyyy-MM-dd HH:mm:ss格式的
但java.sql.Date的valueOf(String str)方法中参数类型只支持"yyyy-mm-dd" 形式的日期的 String 对象所以,要不你就用yyyy-MM-dd 格式,否则就不要用java.sql.Date.valueOf(String s)方法,呵呵,OK,问题解决~~
java.sql.Date的valueOf(String str)方法中参数类型只支持"yyyy-mm-dd" 形式的日期的 String 对象有什么别的方法是可以将
SimpleDateFormat formatter=
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")这种格式的时间添加进数据库呢! 将 字符串 转成 Date
类型的,也还是不能添加进数据库,感觉到了上面这个地方就出错了:pstmt2.setDate(5, sqlDate);
是不是这里的 日期一定要是 java.sql.Date 类型的?有有什么办法可以将Date类型的转换成java.sql.Date 类型的吗?请问!还要劳烦大家一下!
SimpleDateFormat formatter=
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String mydate=formatter.format(Calendar.getInstance().getTime()); java.sql.Date sqlDate=java.sql.Date.valueOf(mydate);你的日期转换没有问题,mydate肯定是yyyy-MM-dd HH:mm:ss的格式
但是你可以看下api,java.sql.Date的valueOf方法中的参数格式为yyyy-mm-dd
所以报日期转换错误
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 年-月-日 时:分:秒明显格式不符!
Exception是NumberFormatException,而不是SQLException,可能说明还没有到数据库这一层就发生错误了.LZ好好看一下传进来的send_id和receive_id是不是真的是Integer...还是"09 09:34:09"...
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 的数据添加进 数据库。用 PreparedStatement pstmt2 = sqlConn
.prepareStatement("insert into member_msg(send_id,recieve_id,readtimes,topic,sendtime,message) values(?,?,?,?,?,?)"); pstmt2.setDate(5, sqlDate); 这里的日期还好象只能是 java.sql.date类型的,而且他格式是:年-月-日。现在请问有没什么办法把 yyyy-MM-dd HH:mm:ss这种格式的时间转换了 再添加进数据库
取代是可以,不过这样的话,这样时间的格式就默认是 "yyyy-MM-dd"
SimpleDateFormat simpleDateTimeFormat = new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
c = Calendar.getInstance(Locale.CHINESE);
String kk_BlacklistVehicleRegister_LARQ_Input = simpleDateTimeFormat.format(c.getTime()) ;//获得服务器时间 LARQ:录入时间转成String再去to_date,我就是这样做的
我的blog
http://heisetoufa.ggblog.com/
论坛
http://www.java2000.net/f218
生成的时间是 yyyy-MM-dd HH:mm:ss 格式,获取是 String kk_BlacklistVehicleRegister_LARQ_Input
怎样把它转成Date类型呢?我在上面的添加语句,好象得是java.sql.date的日期类型。请问怎样转换呢?你的这个 to_date('"+formatter+"','YYYY-MM-DD HH24:MI:SS')" ;是什么?还看不太明白,请说明下好吗?
2、只能把时间格式定 为 yyyy-MM-dd 的这种形式
3、放弃算了。
4、心中还是有疑问:别人是怎么样把那么长的时间添加进数据库的呢?还是时间类型的。?
5、或者别人在添加的时候,用的是 PreparedStatement 吗?