我的SpringBoot应用程序的编译无法创建数据库。
原因:java。sql。SqlSyntaxerErrorException:您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以获取在第1行的“read bit,releaseDate date,primary key(id))engine=InnoDB”附近使用的正确语法
根据堆栈,它来自我的“释放日期”日期或我的类“书籍”中的“读取”布尔值。我假设它在Jpa中失败是由于错误的注释。(这是一个相当广泛的假设,如果我错了,请纠正我)
这里是堆栈
2019-01-21 14:29:21.482 INFO 5472 --- [ main] c.e.S.restapi.postgresql.Application : Starting Application on MSI with PID 5472 (D:\Documents\Coding\Grokonez\clientVue_appRestFulSpringBoot_dataPostGre\SpringBootRestPostgreSQL\target\classes started by Charles LeMagnifique in D:\Documents\Coding\Grokonez\clientVue_appRestFulSpringBoot_dataPostGre\SpringBootRestPostgreSQL)
2019-01-21 14:29:21.486 INFO 5472 --- [ main] c.e.S.restapi.postgresql.Application : No active profile set, falling back to default profiles: default
2019-01-21 14:29:22.216 INFO 5472 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-01-21 14:29:22.280 INFO 5472 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 58ms. Found 1 repository interfaces.
2019-01-21 14:29:22.565 INFO 5472 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$81d566ae] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-01-21 14:29:22.835 INFO 5472 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-01-21 14:29:22.855 INFO 5472 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-01-21 14:29:22.855 INFO 5472 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.14]
2019-01-21 14:29:22.861 INFO 5472 --- [ main] o.a.catalina.core.AprLifecycleListener : An older version [1.2.17] of the APR based Apache Tomcat Native library is installed, while Tomcat recommends a minimum version of [1.2.19]
2019-01-21 14:29:22.861 INFO 5472 --- [ main] o.a.catalina.core.AprLifecycleListener : Loaded APR based Apache Tomcat Native library [1.2.17] using APR version [1.6.3].
2019-01-21 14:29:22.861 INFO 5472 --- [ main] o.a.catalina.core.AprLifecycleListener : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2019-01-21 14:29:22.861 INFO 5472 --- [ main] o.a.catalina.core.AprLifecycleListener : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2019-01-21 14:29:23.900 INFO 5472 --- [ main] o.a.catalina.core.AprLifecycleListener : OpenSSL successfully initialized [OpenSSL 1.0.2o 27 Mar 2018]
2019-01-21 14:29:24.001 INFO 5472 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-01-21 14:29:24.001 INFO 5472 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2462 ms
2019-01-21 14:29:24.123 INFO 5472 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-01-21 14:29:24.628 INFO 5472 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-01-21 14:29:24.662 INFO 5472 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-01-21 14:29:24.711 INFO 5472 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.1.Final}
2019-01-21 14:29:24.712 INFO 5472 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-01-21 14:29:24.773 INFO 5472 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.3.Final}
2019-01-21 14:29:24.856 INFO 5472 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2019-01-21 14:29:24.901 INFO 5472 --- [ main] o.h.e.j.e.i.LobCreatorBuilderImpl : HHH000421: Disabling contextual LOB creation as hibernate.jdbc.lob.non_contextual_creation is true
2019-01-21 14:29:25.448 WARN 5472 --- [ main] o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget encountered exception accepting command : Error executing DDL "create table Book (id bigint not null, description longtext, name varchar(255), read bit, releaseDate date, primary key (id)) engine=InnoDB" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table Book (id bigint not null, description longtext, name varchar(255), read bit, releaseDate date, primary key (id)) engine=InnoDB" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440) [hibernate-core-5.3.1.Final.jar:5.3.1.Final]
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:424) [hibernate-core-5.3.1.Final.jar:5.3.1.Final]
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:315) [hibernate-core-5.3.1.Final.jar:5.3.1.Final]
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:166) [hibernate-core-5.3.1.Final.jar:5.3.1.Final]
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:135) [hibernate-core-5.3.1.Final.jar:5.3.1.Final]
at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:121) [hibernate-core-5.3.1.Final.jar:5.3.1.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:155) [hibernate-core-5.3.1.Final.jar:5.3.1.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72) [hibernate-core-5.3.1.Final.jar:5.3.1.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:310) [hibernate-core-5.3.1.Final.jar:5.3.1.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467) [hibernate-core-5.3.1.Final.jar:5.3.1.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939) [hibernate-core-5.3.1.Final.jar:5.3.1.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) [spring-orm-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) [spring-orm-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) [spring-orm-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) [spring-orm-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) [spring-orm-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804) [spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741) [spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) [spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) [spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) [spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) [spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) [spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083) ~[spring-context-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:853) ~[spring-context-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.2.0.BUILD-SNAPSHOT.jar:2.2.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.2.0.BUILD-SNAPSHOT.jar:2.2.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.0.BUILD-SNAPSHOT.jar:2.2.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.2.0.BUILD-SNAPSHOT.jar:2.2.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.2.0.BUILD-SNAPSHOT.jar:2.2.0.BUILD-SNAPSHOT]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.2.0.BUILD-SNAPSHOT.jar:2.2.0.BUILD-SNAPSHOT]
at com.example.Spring.restapi.postgresql.Application.main(Application.java:10) ~[classes/:na]
Caused by: java.sql.SQLSyntaxErrorException: 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 'read bit, releaseDate date, primary key (id)) engine=InnoDB' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.13.jar:8.0.13]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.13.jar:8.0.13]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.13.jar:8.0.13]
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:782) ~[mysql-connector-java-8.0.13.jar:8.0.13]
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:666) ~[mysql-connector-java-8.0.13.jar:8.0.13]
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-3.3.0.jar:na]
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-3.3.0.jar:na]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ~[hibernate-core-5.3.1.Final.jar:5.3.1.Final]
... 34 common frames omitted
我的application.properties
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/books
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.generate-ddl=true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.datasource.hikari.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
我的pom。xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
我的课堂用书
package com.example.Spring.restapi.postgresql.model;
import lombok.Data;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
//@Table(name = "table")
public class Book implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name = "name")
private String name;
@Column(name = "releaseDate")
@Temporal(TemporalType.DATE)
private Date releaseDate;
@Column(name = "read")
@NotNull
private boolean read;
@Lob
private String description;
public Book() {
}
public Book(String name, Date releaseDate) {
this.name = name;
this.releaseDate = releaseDate;
this.read = false;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getReleaseDate() {
return releaseDate;
}
public void setReleaseDate(Date releaseDate) {
this.releaseDate = releaseDate;
}
public boolean isRead() {
return read;
}
public void setRead(boolean read) {
this.read = read;
}
@Override
public String toString() {
return "Book{" +
"id=" + id +
", name='" + name + '\'' +
", releaseDate=" + releaseDate +
", read=" + read +
'}';
}
}
以下是我尝试过的解决方案:
改为
@Column(name = "checked")
@NotNull
private boolean read;
问题是,如果您将“读取”名称更改为其他名称,则可以正常工作:
#new query
CREATE TABLE Book (
id BIGINT NOT NULL,
description LONGTEXT,
name VARCHAR(255),
checked BIT, #little change
releaseDate DATE,
primary key (id)
) engine = InnoDB
//Code
@Column(name = "checked") //setting name to "checked"
private int read;
这是因为sql本身有一个关键字“READ”。
问题似乎与读取保留关键字有关,请参阅:
关键字和保留字
所以,这个问题一直困扰着我,我似乎无法解决它。出现的错误是: 未捕获错误:语法错误,无法识别的表达式:[{“类型”:“标题”,“子类型”:“h1”,“标签”:“另一个测试表单”},{“类型”:“复选框组”,“标签”:“复选框组”,“名称”:“复选框组-1497353080484”,“值”:[{“标签”:“选项1”,“值”:“选项1”,“选定的”:true}]},{“类型”:“标题”,“子类型”:“
我有一个 springboot 应用程序,我想将我的应用程序连接到 H2 数据库。下面是我的架构。 下面是我的应用程序属性。 但是,我面临以下问题: 由:org.h2.jdbc引起。JdbcSQLSyntaxErrorException:SQL语句“create table employee(id bigint not null auto_increment,email varchar(255),
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: The 'JSON_EXTRACT(all_info, '$' property of null is not a List or Array. 关键是这个sql 用navi
尝试在启动时将数据实现到我的Spring Boot应用程序中。正如我所研究的,它应该是这样工作的: 用户角色类: 模式。sql data.sql 应用属性 但是,如果我尝试这样做,在构建应用程序时只会出现以下错误: SQL语句CREATE TABLE(BIGINT([*] 20)NOTNULL,VARCHAR(255)DEFAULT NULL, PRIMary KEY()ENGINE=INNODB
为了避免DRY,我试图创建一个sql INSERT语句,其中包含变量列名和通过ScalikeJDBC的sql内插填充这些列的数据: 当我把这个叫做: sql语句是:INSERT INTO?(?,?)值(?,?) 参数为:List(My_Table,key,email,42,user@email.com) 您的SQL语法中有一个错误;检查与您的MySQL server版本对应的手册,查找使用“my_
我正在构建一个Web应用程序,并计划使用语音识别和navigator.getUserMedia进行音频输入。 我注意到我的桌面浏览器(Chrome在Mac上,v.31.0.1650.63)两次请求使用麦克风的权限。虽然这对用户来说可能有点烦人,但语音识别和音频输入似乎都可以工作。 但是,如果我在Android(Nexus 7, Android v4.4.2;Chromev31.0.1650.59)