public class DBUtilU {
private static Session scss;
private static SessionFactory sfactory;
static {
Configuration cfg = new Configuration();
cfg.addAnnotatedClass(Userdetails.class);
cfg.addAnnotatedClass(Code.class);
cfg.addAnnotatedClass(Messages.class);
cfg.addAnnotatedClass(Comments.class);
cfg.configure();
new SchemaExport(cfg);
sfactory = cfg.buildSessionFactory();
}
}
public static List<Code> searchCodeTags(String tags) {
List<Code> codelist = new ArrayList<Code>();
try {
scss = sfactory.getCurrentSession();
scss.beginTransaction();
String query = "from Code where Tags=" + tags;
Query queryResult = scss.createQuery(query);
for(Object c : queryResult.list())
codelist.add((Code)c);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return codelist;
}
package UsersProperty;
@Entity
public class Code {
@Id
@GeneratedValue
private int codeId;
private int Rating;
private String fileName;
private String OwnerName;
private String PrjName;
private String Tags;
@ManyToOne()
@JoinColumn(name="userid")
private Userdetails userdetails;
@OneToMany(targetEntity=Comments.class, mappedBy="targetCode")
private List<Comments> cm;
public int getRating() {
return Rating;
}
public void setRating(int rating) {
Rating = rating;
}
public List<Comments> getCm() {
return cm;
}
public void setCm(List<Comments> cm) {
this.cm = cm;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getOwnerName() {
return OwnerName;
}
public void setOwnerName(String ownerName) {
OwnerName = ownerName;
}
public String getPrjName() {
return PrjName;
}
public void setPrjName(String prjName) {
PrjName = prjName;
}
public String getTags() {
return Tags;
}
public void setTags(String tags) {
Tags = tags;
}
public Userdetails getUserdetails() {
return userdetails;
}
public void setUserdetails(Userdetails userdetails) {
this.userdetails = userdetails;
}
public Code(String fileName, String ownerName, String prjName,String tAgs) {
super();
this.fileName = fileName;
OwnerName = ownerName;
PrjName = prjName;
Tags=tAgs;
}
public Code() {
super();
}
public static List<Code> CodeSearch(String TAGS){
return DBUtilU.searchCodeTags(TAGS);
}
}
安慰:
> Hibernate: select code0_.codeId as codeId1_0_, code0_.OwnerName as OwnerNam2_0_, code0_.PrjName as PrjName3_0_, code0_.Rating as Rating4_0_, code0_.Tags as Tags5_0_, code0_.fileName as fileName6_0_, code0_.userid as userid7_0_ from Code code0_ where code0_.Tags=Overloading
Jun 17, 2013 8:38:05 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 42703
Jun 17, 2013 8:38:05 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ERROR: column "overloading" does not exist
Position: 252
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:61)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2036)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1836)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1815)
at org.hibernate.loader.Loader.doQuery(Loader.java:899)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
at org.hibernate.loader.Loader.doList(Loader.java:2522)
at org.hibernate.loader.Loader.doList(Loader.java:2508)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2338)
at org.hibernate.loader.Loader.list(Loader.java:2333)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:490)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1269)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
at DB.DBUtilU.searchCodeTags(DBUtilU.java:117)
at UsersProperty.Code.CodeSearch(Code.java:90)
at Test.Main.main(Main.java:34)
Caused by: org.postgresql.util.PSQLException: ERROR: column "overloading" does not exist
Position: 252
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:56)
... 17 more
问题:
当我searchCodeTags
从DBUtilU
类执行函数时,就会发生这种情况。这是怎么回事
如下更改查询:
String query = "from Code where Tags='" + tags+"'";
否则如下:
String hql = "from Code where Tags=:tags";
Query query = session.createQuery(hql);
query.setParameter("tags",tags);
中相应的比较 ,其中 子句是具有文字,而不是另一列。因此,必须在第一种情况下用引号引起来,或者在第二种情况下使用绑定变量。
嗨,你能帮我解决这个问题吗。我在MySQL DB中连接了这个应用程序,每次运行这个作业从DB中取数据时,我总是会得到这个异常(参见添加了Java类、DAO和方法以及apache DBCP2配置的全栈跟踪)。 null
我无法获取结果,create查询正在执行,但之后将其转换为list无法工作。请帮我解决这个问题。为什么它没有被转换成列表我无法获取结果,创建查询正在被执行,但之后将它转换成列表不起作用。请帮我解决这个问题。为什么它没有被转换成列表 表脚本 bean类 控制器方法是: 错误日志 null AnswerEntity类
目前,我在为springboot项目获取mysql数据时遇到了一个问题: 编辑:Application.Properties 我能够使/test/welcome映射工作,因此我相信我对服务和控制器的实现是正确的。所以我想知道我是不是在访问存储库中的数据库时犯了一个错误,还是应该使用JpaRepository而不是CrudRepository并使用显式查询? 编辑堆栈跟踪:org.springfra
我已经将支持JAR和jdbc驱动程序添加到我的项目中,但我仍然得到了低于例外情况 getting找不到resultset异常错误执行load命令:getting sqlgrammerexception 我的配置文件
这是我的POJO类,名为Student,我为它创建了一个表来更新标记。 这是我的主要班级 当我尝试执行该操作时,它显示了另一个错误,错误是“student0_”。“verson”:无效标识符
org.hibernate.exception.sqlgrammarexception:无法提取ResultSet 以及此控制台错误: 错误:您的SQL语法有错误;查看与您的MariaDB服务器版本相对应的手册,了解第1行“leave leave2_where leave2_.leave_employee=staff0_.staff_code and project1_.proj”附近使用的正确语