hibernate中,根据指定的批量ID查找

Simple_Key 2010-01-18 02:44:59
从XML里面读取出几个ID,我将结果拼接成 '1012','1013','1014' 这种格式,
List tbalist = session.createQuery("from TbActual tba where tba.relevantID in(" + allId + ")").list();
这句代码出来问题 ,请各位大虾帮看看,并说明下原因
谢谢了
...全文
351 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
crazylaa 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 simple_key 的回复:]
是否还有更好的方法来解决,另外,有批量处理的例子可以贴下。结贴率100%,稍微好点的帖子都把分给完了,这个问题还没
[/Quote]
批量的,不知道你要的是不是这个:

public static void readFileWriteBack(String fileName, Connection con)
throws Exception {
String s = "";
File f = new File(fileName);
if (!f.exists()) {
throw new Exception("file doesn't exist....");
}
BufferedReader br = null;
PreparedStatement pstmt = null;
try {
br = new BufferedReader(new InputStreamReader(
new FileInputStream(f)));
String sql = "insert into tbl_report(a,b,c,d)"
+ "values(?,?,?,'2009-12-07')";
pstmt = con.prepareStatement(sql);
// 循环外部准备好prepareStatement;
while ((s = br.readLine()) != null) {
if (s.indexOf("合计") > 0) {
continue;
}
String[] c = s.split("\t");
printArray(c);
if (c.length == 3) {
// 加入批量参数
pstmt.setString(1, c[0]);
pstmt.setString(2, c[1]);
pstmt.setString(3, c[2]);
pstmt.addBatch();
}
}
// 一次执行。
pstmt.executeBatch();
System.out.println("file write back finished");
} catch (Exception e) {
throw e;
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
BearKin 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 simple_key 的回复:]
是否还有更好的方法来解决,另外,有批量处理的例子可以贴下。结贴率100%,稍微好点的帖子都把分给完了,这个问题还没
[/Quote]

你的查询条件在那放着呢 不用IN也是OR 还有别的招么?
islandrabbit 2010-01-18
  • 打赏
  • 举报
回复
mark
Simple_Key 2010-01-18
  • 打赏
  • 举报
回复
是否还有更好的方法来解决,另外,有批量处理的例子可以贴下。结贴率100%,稍微好点的帖子都把分给完了,这个问题还没
bunrise 2010-01-18
  • 打赏
  • 举报
回复
DetachedCriteria criteria = DetachedCriteria.forClass(Entity.class);

criteria.add(Restrictions.in(params, array));
ljjining 2010-01-18
  • 打赏
  • 举报
回复
少个对象
Simple_Key 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 bearkin 的回复:]
引用 6 楼 simple_key 的回复:
引用 5 楼 bearkin 的回复:
session.createQuery("from TbActual tba where tba.relevantID in(" + allId + ")").list();

你可以把语句输出下么 不过既然你说是int型呢 那么
"'1012','1013','1014'"是不是应该改成
"1012,1013,1014"


Sqlserver支持这种模式的,可以用String类型的查int,但是不可以用int的查String.

换下看看..
[/Quote]

HIBERNATE最后将之转义为SQL语句。。。我自己解决掉了。。。。
BearKin 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 simple_key 的回复:]
引用 5 楼 bearkin 的回复:
session.createQuery("from TbActual tba where tba.relevantID in(" + allId + ")").list();

你可以把语句输出下么 不过既然你说是int型呢 那么
"'1012','1013','1014'"是不是应该改成
"1012,1013,1014"


Sqlserver支持这种模式的,可以用String类型的查int,但是不可以用int的查String.
[/Quote]
换下看看..
Simple_Key 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 bearkin 的回复:]
session.createQuery("from TbActual tba where tba.relevantID in(" + allId + ")").list();

你可以把语句输出下么 不过既然你说是int型呢 那么
"'1012','1013','1014'"是不是应该改成
"1012,1013,1014"
[/Quote]

Sqlserver支持这种模式的,可以用String类型的查int,但是不可以用int的查String.
BearKin 2010-01-18
  • 打赏
  • 举报
回复
session.createQuery("from TbActual tba where tba.relevantID in(" + allId + ")").list();

你可以把语句输出下么 不过既然你说是int型呢 那么
"'1012','1013','1014'"是不是应该改成
"1012,1013,1014"
Simple_Key 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 warison2008 的回复:]
使用criteria方式
[/Quote]

能具体点吗?谢谢了
Simple_Key 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bearkin 的回复:]
把语句输出下 你的那个属性是什么类型的 是VARCHAR么? 还是NUMBER?
[/Quote]

是int类型的
烟雨鹏城 2010-01-18
  • 打赏
  • 举报
回复
使用criteria方式
BearKin 2010-01-18
  • 打赏
  • 举报
回复
把语句输出下 你的那个属性是什么类型的 是VARCHAR么? 还是NUMBER?

67,550

社区成员

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

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