67,550
社区成员




String sql ="INSERT INTO `sweet_tree`(`code`,`parent`,`name`) SELECT code,parent,name FROM sweet_tree_00049; INSERT INTO `sweet_tree`(`code`,`parent`,`name`) SELECT code,parent,name FROM sweet_tree_00001;";
Session dbss = HibernateSessionFactory.getSession();
try
{
dbss.beginTransaction();
dbss.createSQLQuery(sql).executeUpdate();
dbss.getTransaction().commit();
} finally
{
if (dbss != null)
dbss.close();
}
[/quote]
老哥你这个是一条sql吗
String sql ="INSERT INTO `sweet_tree`(`code`,`parent`,`name`) SELECT code,parent,name FROM sweet_tree_00049; INSERT INTO `sweet_tree`(`code`,`parent`,`name`) SELECT code,parent,name FROM sweet_tree_00001;";
还能这样写吗?中间还有分号的吗?
你可吧 insert分开两次来执行,还有结尾在java代码中不要加分号了吧
[/quote]
不是只插入两个表,是有N多个表要这样处理,这个是定位问题后简化的代码。
如果分开执行的话,耗费的时间太长
String sql ="INSERT INTO `sweet_tree`(`code`,`parent`,`name`) SELECT code,parent,name FROM sweet_tree_00049; INSERT INTO `sweet_tree`(`code`,`parent`,`name`) SELECT code,parent,name FROM sweet_tree_00001;";
Session dbss = HibernateSessionFactory.getSession();
try
{
dbss.beginTransaction();
dbss.createSQLQuery(sql).executeUpdate();
dbss.getTransaction().commit();
} finally
{
if (dbss != null)
dbss.close();
}
[/quote]
老哥你这个是一条sql吗
String sql ="INSERT INTO `sweet_tree`(`code`,`parent`,`name`) SELECT code,parent,name FROM sweet_tree_00049; INSERT INTO `sweet_tree`(`code`,`parent`,`name`) SELECT code,parent,name FROM sweet_tree_00001;";
还能这样写吗?中间还有分号的吗?
你可吧 insert分开两次来执行,还有结尾在java代码中不要加分号了吧
CREATE TABLE `sweet_tree` (
`id` bigint(20) DEFAULT NULL,
`code` varchar(128) DEFAULT NULL,
`parent` varchar(128) DEFAULT NULL,
`name` varchar(156) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
这个是表结构
String sql ="INSERT INTO `sweet_tree`(`code`,`parent`,`name`) SELECT code,parent,name FROM sweet_tree_00049; INSERT INTO `sweet_tree`(`code`,`parent`,`name`) SELECT code,parent,name FROM sweet_tree_00001;";
Session dbss = HibernateSessionFactory.getSession();
try
{
dbss.beginTransaction();
dbss.createSQLQuery(sql).executeUpdate();
dbss.getTransaction().commit();
} finally
{
if (dbss != null)
dbss.close();
}