insert into select 插入不进去数据怎么回事?高手请教下哈!!

MJaney 2013-05-29 09:59:56
代码如下:
//大量数据的插入需要分批执行
while(!statistics_start.equals(init_date_from)){
String statistics_end=DateTool.getTimeStringDayPlus(statistics_start, +1);
sql="insert into tb_request_month_temp (requesttime,username,devnumber,modulename,devtype,version)
(select requesttime,username,devnumber,modulename,devtype,version
from v_request where REQUESTTIME >= to_date(?,'yyyy-MM-dd HH24:mi:ss') AND REQUESTTIME < to_date(?,'yyyy-MM-dd HH24:mi:ss'))";

PreparedStatement pstate=connDB.prepareStatement(sql);
try {
pstate.setString(1, statistics_start);
pstate.setString(2, statistics_end);
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println(sql);
_log.info(sql);
try {
flag=pstate.executeUpdate();
System.out.println(flag);

} catch (SQLException e) {
e.printStackTrace();
}
if(flag==-1)return false;
statistics_start=DateTool.getTimeStringDayPlus(statistics_start, +1);

}

执行这段代码,数据库没有数据,在数据库里执行打印出来的sql语句有数据,
有哪位高手能看出代码里的问题呢?为什么程序不能插入数据呢?

并且,flag打印是有值的
...全文
839 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
MJaney 2013-05-30
  • 打赏
  • 举报
回复
分开不行,分开的话,效率很低,速度很慢!!!
hxm 2013-05-30
  • 打赏
  • 举报
回复
sql语句 :insert into test(name,pass)values('"+name+"','"+pass+"') String name=request.getParam("name"); : select from test where name='"+name+"'
MJaney 2013-05-30
  • 打赏
  • 举报
回复
我在flag=pstate.executeUpdate();
的下面加上了connDB.getConnection().commit();
结果数据库里依然没有数据,传入的参数打印出来没有问题,改成where REQUESTTIME >= ?
?以setTimesStamp()的形式,程序不通过,代码如下:



菖蒲老先生 2013-05-29
  • 打赏
  • 举报
回复
第一反应就是没有事务内commit。。。 flag=pstate.executeUpdate(); 的下面加上 connDB.commit(); 或者你传入的参数不对。。。 where REQUESTTIME >= ? ?以setTimesStamp()的形式试试。。。

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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