• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

테이블 찾을 수 없음

23.05.31 16:17 작성 조회수 324

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:

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

답변 1

답변을 작성해보세요.

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2023.06.02

안녕하세요, 인프런 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 파일에서 사용한 테이블명이 정확한지 확인해주세요.

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

감사합니다.