- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个 DAO Hibernate 映射类。关系是一对多的双向关系。当我尝试添加新设置时,出现以下错误。
jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key, updated_by, updated_time, appType_id) values ('Mxxd', '2015-12-17 11:09:' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
at com.mysql.jdbc.Util.getInstance(Util.java:383)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1901)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2113)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2049)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2034)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:147)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3032)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3558)
at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:98)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:492)
at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:197)
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:181)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:216)
at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:334)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:289)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:195)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:715)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:707)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:702)
at com.ips.tvadmindao.services.TvAppTypeService.addAppType(TvAppTypeService.java:53)
at com.xxx.tvadmindao.services.Application.main(Application.java:50)
2015-12-17 11:09:37 WARN SqlExceptionHelper:144 - SQL Error: 1064, SQLState: 42000
2015-12-17 11:09:37 ERROR SqlExceptionHelper:146 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key, updated_by, updated_time, appType_id) values ('Kalla', '2015-12-17 11:09:' at line 1
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:80)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:211)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3032)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3558)
at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:98)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:492)
at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:197)
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:181)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:216)
at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:334)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:289)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:195)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:715)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:707)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:702)
at com.xxx.tvadmindao.services.TvAppTypeService.addAppType(TvAppTypeService.java:53)
at com.xxx.tvadmindao.services.Application.main(Application.java:50)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key, updated_by, updated_time, appType_id) values ('MenukaD', '2015-12-17 11:09:' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
at com.mysql.jdbc.Util.getInstance(Util.java:383)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1901)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2113)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2049)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2034)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:147)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
... 23 more
这里我添加了用于添加设置类型的方法。
public boolean addAppType() {
//boolean success = false;
// add app and setting together
String appType_name = "AAAA";
String created_by = "Mxxxd";
TvAppsType_Settings setting = new TvAppsType_Settings();
setting.setCreated_by(created_by);
setting.setCreated_time(new LocalDateTime());
setting.setKey("Host2");
setting.setUpdated_by(created_by);
setting.setUpdated_time(new LocalDateTime());
TvAppsType apptype2 = (TvAppsType)session.get(TvAppsType.class, 4);
setting.setApptypes(apptype2);
session.save(setting);
if (!HibernateUtil.INSTANCE.commitTransaction())
return false;
logger.info("Exited : " + "addAppType(String appType_name, String created_by)");
return true;
}
也有 DAO 类。
@Entity
@Table(name = "tvapps_type_settings")
public class TvAppsType_Settings {
@Id //primary key
@GeneratedValue(strategy = GenerationType.IDENTITY)//strategy for generating auto generated number
@Column(name = "settingType_id", nullable = false)
private int settingType_id;
/*@Column(name = "appType_id", insertable=false , updatable=false)
private int appType_id;*/
@ManyToOne(cascade= CascadeType.ALL)
@JoinColumn(name= "appType_id",insertable=false, updatable=false)
private TvAppsType apptypes;
@Column(name = "key")
private String key;
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
@Column(name = "created_time", nullable = false)
private LocalDateTime created_time;
@Column(name = "created_by", nullable = false)
private String created_by;
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
@Column(name = "updated_time", nullable = false)
private LocalDateTime updated_time;
@Column(name = "updated_by", nullable = false)
private String updated_by;
public TvAppsType getApptypes() {
return apptypes;
}
public void setApptypes(TvAppsType apptypes) {
this.apptypes = apptypes;
}
public int getSettingType_id() {
return settingType_id;
}
public void setSettingType_id(int settingType_id) {
this.settingType_id = settingType_id;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public LocalDateTime getCreated_time() {
return created_time;
}
public void setCreated_time(LocalDateTime created_time) {
this.created_time = created_time;
}
public String getCreated_by() {
return created_by;
}
public void setCreated_by(String created_by) {
this.created_by = created_by;
}
public LocalDateTime getUpdated_time() {
return updated_time;
}
public void setUpdated_time(LocalDateTime updated_time) {
this.updated_time = updated_time;
}
public String getUpdated_by() {
return updated_by;
}
public void setUpdated_by(String updated_by) {
this.updated_by = updated_by;
}
}
TvAppsType DAO 类。
@Entity
@Table(name = "tvapps_type")
public class TvAppsType {
@Id //primary key
@GeneratedValue(strategy = GenerationType.IDENTITY)//strategy for generating auto generated number
@Column(name = "appType_id", nullable = false)
private int appType_id;
@Column(name = "appType_name", nullable = false)
private String appType_name;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "appType_id",nullable = false)
private List<TvAppsType_Settings> tvsettings = new ArrayList<TvAppsType_Settings>();
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
@Column(name = "created_time", nullable = false)
private LocalDateTime created_time;
@Column(name = "created_by", nullable = false)
private String created_by;
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
@Column(name = "updated_time", nullable = false)
private LocalDateTime updated_time;
@Column(name = "updated_by", nullable = false)
private String updated_by;
public List<TvAppsType_Settings> getTvsettings() {
return tvsettings;
}
public void setTvsettings(List<TvAppsType_Settings> tvsettings) {
this.tvsettings = tvsettings;
}
public int getAppType_id() {
return appType_id;
}
public void setAppType_id(int appType_id) {
this.appType_id = appType_id;
}
public String getAppType_name() {
return appType_name;
}
public void setAppType_name(String appType_name) {
this.appType_name = appType_name;
}
public LocalDateTime getCreated_time() {
return created_time;
}
public void setCreated_time(LocalDateTime created_time) {
this.created_time = created_time;
}
public String getCreated_by() {
return created_by;
}
public void setCreated_by(String created_by) {
this.created_by = created_by;
}
public LocalDateTime getUpdated_time() {
return updated_time;
}
public void setUpdated_time(LocalDateTime updated_time) {
this.updated_time = updated_time;
}
public String getUpdated_by() {
return updated_by;
}
public void setUpdated_by(String updated_by) {
this.updated_by = updated_by;
}
}
你们能帮我解决这个错误吗?
最佳答案
您的 MySQL 服务器不喜欢字段名 key
,并且您的持久性提供程序无法正确处理该字段。一种选择是将字段 key
重命名为其他名称(如果您可以的话)。
或者,
@Column(name="`key`")
应该可以。
关于java - jdbc.exceptions.jdbc4.MySQLSyntaxErrorException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34342667/
我有一个像下面这样的代码。我已经尝试了堆栈中的其他解决方案,但似乎没有任何效果。生成错误的 Java 代码如下所示。 public Connection getConnection() {
我有这段代码: String check="SELECT COUNT(*) as check FROM recordstudent WHERE STUDENT_ID="+T_STUDENT_I
在我的项目中,我编写了一些代码来从数据库表中搜索员工姓名并将其加载到 jcombobox 中。 表名:employee 列名:empid(Primarykey), emp_name, position
我有一个奇怪的问题。当我在以下代码段中执行查询时,它会抛出 MySQLSyntaxErrorException 并显示以下消息: You have an error in your SQL synta
我在这里看到了很多关于我的问题的答案,但找不到解决方案。我正在读取 Excel 文件并存储在 mysql 数据库中。这是我的代码 PreparedStatement sql_statement = (
我正在尝试更新我的 jtable(更改值并按 Enter 键),但出现错误。由于大小原因,错误未完整。我认为其余部分只是 c3p0 池连接工具生成的不相关信息。 假设 起初,我认为这可能是 c3p0
我在 spring 框架的 mapper.xml 中遇到一些问题 失败: check the manual that corresponds to your MySQL server version
这个问题已经有答案了: mysql prepared statement error: MySQLSyntaxErrorException (2 个回答) 已关闭 8 年前。 我花了几个小时研究看起来
我试图从 java 桌面程序在 mysql 中创建一个表,但我收到了 MySqlSyntaxErrorException。 查询是: CREATE TABLE FileXFascia(fila0 In
这是错误: run: Mon Mar 25 05:22:00 SGT 2019 WARN: Establishing SSL connection without server's identity
我使用准备语句编写了 select 语句。每次尝试运行它都会出现此错误。我是怎么克服这个错误的?我的 jdbc 连接器是 mysql-connector-java-5.1.13-bin.jar。我的代
session.getAttribute('loginId')//giving 1 ResultSet rs=st.executeQuery("select * from interest where
String sql = "INSERT INTO order " + "(customerid, pant, shirt, date) " + "VALUES ('" + jTextField
我正在使用 Java 将一些数据插入到 mysql 中。但是将撇号(标点符号)放入数据中(附近的每周跟踪器表明工作增长)它给了我 MySQLSyntaxErrorException。请给我适当的解决方
我对使用 Java 的 MySQL 还很陌生,但是我已经执行了一些成功的 INSERT 查询,但是似乎无法在没有 MySQLSyntaxErrorException 异常的情况下执行 CREATE T
我目前正在使用 hibernate 构建一个基于网络的小工具。我使用 Tomcat v7.0 服务器在 eclipse 中测试该站点。我的数据库在 Linux 上使用 MySQL 5.6 版。 现在,
我看过几个相关的问题及其答案,但这对我的案子没有帮助。 我有一个 Spring boot 应用程序,我在其中使用 Jhipster 创建了实体,另外我自己添加了一些手动变更日志变更集。 我有一个医生实
当我执行以下查询时抛出以下异常 Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an er
我的目标是向我创建的现有表中添加一个新行。但是,我收到以下错误。 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have
我有以下 Java 代码: String query = "Select 1 from myTable where name = ? and age = ?"; PreparedStatement s
我是一名优秀的程序员,十分优秀!