2017-07-27 31 views
1

我有org.springframework.jdbc.datasource.init.ScriptStatementFailedException從一個SQL腳本我正在使用h2在春天項目。ScriptStatementFailedException在SQL文件

SET @TEASER = '<p> Text Text Text</p>' 
SET @BODY = '<p> Lorem ipsum dolor sit amet</p>' 

insert into author(id,first_name,last_name,email) values(1,'Dan','Vega','[email protected]'); 
insert into post(id,title,slug,teaser,body,author_id,posted_on) values(1,'Spring boot rocks','spring-boot-rocks',@TEASER,@BODY,1,CURRENT_TIMESTAMP); 
insert into post(id,title,slug,teaser,body,author_id,posted_on) values(2,'Spring boot is kew;','spring-boot-is-kewl',@TEASER,@BODY,1,CURRENT_TIMESTAMP); 

這是郵政類我使用

@Entity 
public class Post { 

@Id 
@GeneratedValue(strategy = GenerationType.AUTO) 
private Long id; 
private String title; 
@Column(columnDefinition = "TEXT") 
private String body; 
@Column(columnDefinition = "TEXT") 
private String teaser; 
private String slug; 
@CreatedDate @Column(columnDefinition = "TIMESTAMP") 
private Date postedOn; 
@ManyToOne 
private Author author; 
// constructors, getters and setters 

錯誤 - 它重複每次有什麼與郵政類類,在這種情況下的HomeController有一個PostService類自動裝配該具有PostRepository自動裝配屬性。

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'homeController': Unsatisfied dependency expressed through method 'setPostService' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'postService': Unsatisfied dependency expressed through method 'setPostRepository' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'postRepository': Cannot create inner bean '(inner bean)#3f6f9cef' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3f6f9cef': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Talon/Desktop/java%20netbeans/01/SpringBootH2Demo/target/classes/data-h2.sql]: SET @TEASER = '<p> Text Text Text</p>' SET @BODY = '<p> Lorem ipsum dolor sit amet</p>' insert into author(id,first_name,last_name,email) values(1,'Dan','Vega','[email protected]'); nested exception is org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "SET @TEASER = '<p> Text Text Text</p>' SET[*] @BODY = '<p> Lorem ipsum dolor sit amet</p>' INSERT INTO AUTHOR(ID,FIRST_NAME,LAST_NAME,EMAIL) VALUES(1,'Dan','Vega','[email protected]') "; SQL statement: 
SET @TEASER = '<p> Text Text Text</p>' SET @BODY = '<p> Lorem ipsum dolor sit amet</p>' insert into author(id,first_name,last_name,email) values(1,'Dan','Vega','[email protected]') [42000-196] 

如果我從sql文件中刪除@TEASER和@BODY,並從後置值插入它的作品。我拼錯了什麼?

回答

0

您可能忘記在SET語句之後放置分號。

SET @TEASER ='Text Text Text'; SET @BODY ='Lorem ipsum dolor sit amet'; 試試這個,如果作品

+0

是的,我不太熟悉sql,非常感謝。 – MrSir