在休眠中打开查询
我在我的问题中使用了 struts 和 hibernate。我尝试了以下查询
String hql ="insert into "+
"OPENQUERY(OracleLinkedServer, \'SELECT * FROM report_access_log\') "+
"(CALLINGHOST, ACCESSTIMESTAMP, HTTPREQUESTMETHOD, ACCESSURL,"+
"HTTPRESPONSECODE, HTTPRESPONSETIMEMILLI, USERNAME, REPORTNAME, ID)"+
" values "+
"(:CALLINGHOST,:ACCESSTIMESTAMP,:HTTPREQUESTMETHOD,:ACCESSURL,:HTTPRESPONSECODE," +
":HTTPRESPONSETIMEMILLI,:USERNAME,:REPORTNAME,"+
"(select * from OPENQUERY(OracleLinkedServer,"+
"\'select SQ_RPT_ACC_LOG_ID.nextval from dual\')))";
Query query=session.createQuery(hql);
query.setString("CALLINGHOST", userLogReport.get(0).toString());
query.setDate("ACCESSTIMESTAMP", (Date)userLogReport.get(1));
query.setString("HTTPREQUESTMETHOD", userLogReport.get(2).toString());
query.setString("ACCESSURL", userLogReport.get(3).toString());
query.setString("HTTPRESPONSECODE", userLogReport.get(4).toString());
query.setInteger("HTTPRESPONSETIMEMILLI", (Integer)userLogReport.get(5));
query.setString("USERNAME", userLogReport.get(6).toString());
query.setString("REPORTNAME", userLogReport.get(7).toString());
控制台上打印的查询如下
insert into OPENQUERY(OracleLinkedServer, 'SELECT * FROM report_access_log')
(CALLINGHOST, ACCESSTIMESTAMP, HTTPREQUESTMETHOD, ACCESSURL,HTTPRESPONSECODE,
HTTPRESPONSETIMEMILLI, USERNAME, REPORTNAME, ID) values
(:CALLINGHOST,:ACCESSTIMESTAMP,:HTTPREQUESTMETHOD,:ACCESSURL,:HTTPRESPONSECODE:HTTPRESPONSE
TIMEMILLI,:USERNAME,:REPORTNAME,(select * from OPENQUERY(OracleLinkedServer,'select
SQ_RPT_ACC_LOG_ID.nextval from dual')))
我在第 79 列处收到查询语法异常,即 (CALINGHOST,...
但是当我在 SQL 中运行查询时,它正在执行。查询如下
insert into OPENQUERY(OracleLinkedServer, 'SELECT * FROM report_access_log')
(CALLINGHOST, ACCESSTIMESTAMP, HTTPREQUESTMETHOD, ACCESSURL,HTTPRESPONSECODE,
HTTPRESPONSETIMEMILLI, USERNAME, REPORTNAME, ID) values
('10.87.192.246','GET','/cci/bby/ImageViewer/viewImages.action','200',6,'su','Insert
Review',(select * from OPENQUERY(OracleLinkedServer,'select SQ_RPT_ACC_LOG_ID.nextval
from dual')))
请解释一下问题并为我提供一个从 Java 执行它的解决方案。 提前致谢。
I am using struts and hibernate in my problem. I tried the following query
String hql ="insert into "+
"OPENQUERY(OracleLinkedServer, \'SELECT * FROM report_access_log\') "+
"(CALLINGHOST, ACCESSTIMESTAMP, HTTPREQUESTMETHOD, ACCESSURL,"+
"HTTPRESPONSECODE, HTTPRESPONSETIMEMILLI, USERNAME, REPORTNAME, ID)"+
" values "+
"(:CALLINGHOST,:ACCESSTIMESTAMP,:HTTPREQUESTMETHOD,:ACCESSURL,:HTTPRESPONSECODE," +
":HTTPRESPONSETIMEMILLI,:USERNAME,:REPORTNAME,"+
"(select * from OPENQUERY(OracleLinkedServer,"+
"\'select SQ_RPT_ACC_LOG_ID.nextval from dual\')))";
Query query=session.createQuery(hql);
query.setString("CALLINGHOST", userLogReport.get(0).toString());
query.setDate("ACCESSTIMESTAMP", (Date)userLogReport.get(1));
query.setString("HTTPREQUESTMETHOD", userLogReport.get(2).toString());
query.setString("ACCESSURL", userLogReport.get(3).toString());
query.setString("HTTPRESPONSECODE", userLogReport.get(4).toString());
query.setInteger("HTTPRESPONSETIMEMILLI", (Integer)userLogReport.get(5));
query.setString("USERNAME", userLogReport.get(6).toString());
query.setString("REPORTNAME", userLogReport.get(7).toString());
The query printed on the console is as follows
insert into OPENQUERY(OracleLinkedServer, 'SELECT * FROM report_access_log')
(CALLINGHOST, ACCESSTIMESTAMP, HTTPREQUESTMETHOD, ACCESSURL,HTTPRESPONSECODE,
HTTPRESPONSETIMEMILLI, USERNAME, REPORTNAME, ID) values
(:CALLINGHOST,:ACCESSTIMESTAMP,:HTTPREQUESTMETHOD,:ACCESSURL,:HTTPRESPONSECODE:HTTPRESPONSE
TIMEMILLI,:USERNAME,:REPORTNAME,(select * from OPENQUERY(OracleLinkedServer,'select
SQ_RPT_ACC_LOG_ID.nextval from dual')))
i get a query syntax exception at column no 79 which is (CALLINGHOST,...
But when i ran the query in SQL it is getting executed. The query is as follows
insert into OPENQUERY(OracleLinkedServer, 'SELECT * FROM report_access_log')
(CALLINGHOST, ACCESSTIMESTAMP, HTTPREQUESTMETHOD, ACCESSURL,HTTPRESPONSECODE,
HTTPRESPONSETIMEMILLI, USERNAME, REPORTNAME, ID) values
('10.87.192.246','GET','/cci/bby/ImageViewer/viewImages.action','200',6,'su','Insert
Review',(select * from OPENQUERY(OracleLinkedServer,'select SQ_RPT_ACC_LOG_ID.nextval
from dual')))
Please explain the problem and provide me a solution for executing it from Java.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HQL 和 SQL 是两种不同的语言。 HQL 适用于 Hibernate 实体、它们的属性以及它们之间的关联。 SQL 适用于数据库表和列。
使用
而不是
HQL and SQL are two different languqges. HQL works on Hibernate entities, their properties, and associations between them. SQL works on database tables and columns.
Use
rather than