如何解决在JPQL的本机查询中使用BETWEEN
我试图在JPQL中使用Traceback (most recent call last):
File "python",line 5,in <module>
File "python",line 3,in printPreviousAndNext
TypeError: can only concatenate str (not "int") to str
进行查询,我已经在SQL中对其进行了测试,并且可以正常工作,但是当我在JPQL中实现时,出现了错误:
BETWEEN
我不明白为什么Caused by: javax.persistence.PersistenceException:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5):
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException:
Incorrect syntax near ':'.
Error Code: 102"
附近有错误,有人可以帮我解决吗?
这是我的代码:
:
解决方法
根据this answer,EclipseLink在使用?
前缀而不是:
的本机查询中设置命名参数的语法略有不同
public List<Object[]> reportPendapatan(String tahun) {
String tahun1 = tahun +"-01-01";
String tahun2 = tahun +"-12-31";
return em.createNativeQuery(
"SELECT p.tanggal,m.nama,pg.nama_jenis,g.nama_guru,pg.harga_masuk "
+ "FROM Pendaftaran p,Murid m,pengajian pg,Guru g "
+ "WHERE p.id_murid = m.id_murid and p.tanggal between ?tahun and ?tahun2 "
+ "and p.id_guru = g.id_guru and p.id_jenis = pg.id_jenis and p.status=4")
.setParameter("tahun",tahun1)
.setParameter("tahun2",tahun2)
.getResultList();
}
其他选择是分别对tahun1
和tahun2
使用位置参数 1和2:
// ...
return em.createNativeQuery(
"SELECT p.tanggal,Guru g "
+ "WHERE p.id_murid = m.id_murid and p.tanggal between ? and ? "
+ "and p.id_guru = g.id_guru and p.id_jenis = pg.id_jenis and p.status=4")
.setParameter(1,tahun1)
.setParameter(2,tahun2)
.getResultList();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。