从Oracle中取sysdate问题。 取出的createTime为null,经过打印hash,终于找到问题所在。原来我将取出Oracle的sysdate命名一个别名systemTime,后面就用systemTime= hash.get("systemTime").toString(); 而hash中真正的键是systemtime.下面是修正后的代码:public class OracleSystemTime{ public String getSystemTime() { String systemTime=null; String sql = "select to_char(sysdate,"yyyy-mm-dd hh24:mi:ss") systemtime from dual"; Hashtable hash = DBHelper.getValue(sql); if(hash.isEmpty()) systemTime= null; else systemTime= hash.get("systemtime").toString(); return systemTime; }} 打印的结果:createTime=2009-12-21 20:00:35打印的SQL:insert into a_chat_title (id,room_title, create_user_id, begin_time, room_id) values(a_chat_title_SEQ.nextval,"test","admin","2009-12-21 20:00:35",10) 将取出的sysdate回插到数据库中。 注意to_date函数在insert语句中的用法,其中用到的变量一定要用"" stringname ""的格式表示。(我晕,花了这么长时间问题竟然出在这个地方。网上也没有相关的解答) 如:to_date("" createTime "","yyyy-mm-dd hh24:mi:ss")。下面是修正后的代码:OracleSystemTime systemTime=new OracleSystemTime();String createTime =systemTime.getSystemTime();String insertSql = "insert into a_chat_title (id,room_title, create_user_id, begin_time, room_id)" " values(a_chat_title_SEQ.nextval,"" room_title "","" userId "",to_date("" createTime "","yyyy-mm-dd hh24:mi:ss")," roomId ")";Oracle的dual表作用Oracle内置角色connect与resource的权限相关资讯 oracle
- [INS-32052] Oracle基目录和Oracle (07/22/2014 07:41:41)
- Oracle 4个大对象(lobs)数据类型 (02/03/2013 12:33:05)
- Oracle按时间段分组统计 (07/26/2012 10:36:48)
| - [Oracle] dbms_metadata.get_ddl的 (07/12/2013 07:37:30)
- Liferay Portal 配置使用Oracle和 (07/31/2012 20:07:18)
- Concurrent Request:Inactive (07/20/2012 07:44:05)
|
本文评论 查看全部评论 (0)