inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발

테이블 찾을 수 없음

494

김훈진 (KHJ)

작성한 질문수 3

0

참고로 user테이블이 이미 다른 database에서 사용중인것 같아서 user_table로 이름 지정했습니다.

 

테이블은 잘 만들어졌습니다.

그런데

data.sql에 해당 Unable to resolve table 'user_table' 문구를 가진 빨간 전구 user_table에 빨간 불이 들어옵니다.

insert into user_table values (1, sysdate(), 'User1', 'test1111', '701010-1111111');
insert into user_table values (2, sysdate(), 'User2', 'test2222', '801010-1111111');
insert into user_table values (3, sysdate(), 'User3', 'test3333', '901010-1111111');

 


@Entity
@Table(name = "user_table")
public class User {
    @Id
    @GeneratedValue
    private Integer id;

    @Size(min = 2, message = "Name은 2글자 이상 입력해 주세요!")
    @ApiModelProperty(notes = "사용자 이름을 입력해 주세요.")
    private String name;
    @Past
    @ApiModelProperty(notes = "사용자 등록일을 입력해 주세요.")
    private Date joinDate;

    @ApiModelProperty(notes = "사용자 패스워드를 입력해 주세요.")
    private String password;
    @ApiModelProperty(notes = "사용자 주민번호를  입력해 주세요.")
    private String ssn;
}
spring:
  messages:
    basename: messages
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
  datasource:
    url: jdbc:h2:mem:testdb;DATABASE_TO_UPPER=false

  jpa:
    show-sql: true
    hibernate:
      ddl-auto: create-drop


  h2:
    console:
      enabled: true
      path: "/h2-console"

.yml 파일에도 대소문자 무시도 추가해 보았지만 여전히 실행시 이런 에러가 발생하고요

Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/D:/intelliJavaPractice/restful-web-service/target/classes/data.sql]: insert into user_table values (1, sysdate(), 'User1', 'test1111', '701010-1111111'); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "user_table" not found (this database is empty); SQL statement:


Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "user_table" not found (this database is empty); SQL statement:

어떻게 해야 해결이 될까요. 도움주시면 정말 감사하겠습니다.

rest-api spring-boot

답변 1

0

인프런 AI 인턴

안녕하세요, 인프런 AI 인턴입니다.

data.sql 파일에서 ‘user_table’을 참조하지만, 해당 테이블이 생성되지 않았다는 에러가 나타납니다.
해당 문제 해결을 위해, 다음과 같은 점을 확인해보세요.

  1. 테이블 생성
    처음에 말씀하신대로 user테이블이 이미 다른 database에서 사용중인 것 같아 user_table로 이름 지정했다면, user 테이블을 생성한 후에 해당 테이블을 user_table로 rename 한 후에 아래와 같이 data.sql 파일을 수정해주세요.
    RENAME TABLE user TO user_table;

  2. data.sql파일 매핑
    data.sql 파일에서 사용한 테이블명이 정확한지 확인해주세요.

이와 같은 조치를 취해도 문제가 해결되지 않는다면, 해당 문제와 관련된 추가적인 정보가 필요할 수 있습니다. 이 경우, 에러 메시지와 함께 더 자세한 오류 내용을 공유해주시면 더 정확한 답변을 제공할 수 있을 것 같습니다.

감사합니다.

JPA

0

63

1

jpa dependency를 추가하고 SecurityConfig클래스에서 오류가 납니다.

0

72

1

웹 브라우저 400 bad request

0

73

1

@Size는 되는데 @Past는 안 됩니다.

0

65

1

pdf 자료는 없나요?

0

76

2

locale 정보가 null 이면 무조건 messages_ko.properties이 호출 되는 문제

0

91

2

Swagger 강의, Unable to infer base url 이거 뜨시는 분들 도움되시라고

0

122

1

강의에서나온 화면 피피티

0

161

1

HelloWorldBean 관련 에러

0

189

2

Swagger API 3.x 오류..

0

223

1

java: variable message not initialized in the default constructor 에러는 어찌하면 좋을까요?

1

283

1

현재 GIT에 올리신 소스를 실행해봤습니다.

0

191

2

고양이 소리가 귀엽네요 !!

0

140

2

git에서 소스받고 실습중인데

0

120

1

post가 안되요

0

107

1

한국어 같은 경우 언어코드인 messages_ko.properties 로 생성하는게 더 좋지 않나요?

0

169

2

리턴타입으로서 EntityModel<User> 와 ResponseEntity질문

0

107

1

예외처리쪽 관련 질문있습니다.

0

161

2

엔티티가 바로 응답으로 나가도 되나요??

0

230

2

안녕하세여 Cannot invoke "co.kr.joneconsulting.resfulservice.repository.PostRepository.save(Object)" because "this.postRepository" is null

0

142

2

사용자 등록하고 나서 H2 에서 보면 신규 사용자의 password, ssn 이 null 로 되어 있습니다.

0

144

2

ApplictionContext 질문

0

196

2

롬북이 안먹히는것같아요

0

159

1

인텔리제이에서스프링부트 파일 실행하면

0

242

1