Database not found, and IFEXISTS=true, so we cant auto-create it

后端 未结 17 3030
不思量自难忘°
不思量自难忘° 2020-12-15 06:20

I am getting error after opening the h2 database console. I enter database name but it is showing database not found error:

Database \"C:/Users/Barlek

17条回答
  •  情书的邮戳
    2020-12-15 07:11

    By degrading the version, the H2 DB is working but table i am unable to see. Code snippet

    Controller

    @RestController
    public class CurrencyExchangeController {
    
        @Autowired
        private Environment env;
        @GetMapping("/currency-exchange/from/{from}/to/{to}")
        public CurrencyExchange retriveCurrencyExchange(@PathVariable String from,@PathVariable String to)
        {
            CurrencyExchange currencyExchange = new CurrencyExchange(1000L, from, to, BigDecimal.valueOf(65));
            currencyExchange.setPort(Integer.parseInt(env.getProperty("local.server.port")));
            return currencyExchange;
    
        }
    

    POJO

    @Entity
    public class CurrencyExchange {
        @Id
        private Long id;
        @Column(name ="currency_from")
        private String from;
        @Column(name ="currency_to")
        private String to;
        @Column(name ="conversion_multiple")
        private BigDecimal conversion;
        private int port;
    

    Spring boot main

    @SpringBootApplication
    @ComponentScan(basePackages = {"com.example"})
    public class CurrencyExchangeServiceApplication {
    
        public static void main(String[] args) throws SQLException {
            SpringApplication.run(CurrencyExchangeServiceApplication.class, args);
    
        }
    

    app.prop

    spring.application.name=currency-exchange-service
    server.port=8000
    
    spring.jpa.show-sql=true
    spring.h2.console.enabled=true
    
    data.sql file
    insert into currency_exchange(id,currency_from,currency_to,conversion_multiple,port)
    values(1001,'USD','INR',65,0);
    insert into currency_exchange(id,currency_from,currency_to,conversion_multiple,port)
    values(1002,'EUR','INR',75,0);
    

提交回复
热议问题