小编Mat*_*ari的帖子

Spring boot 与 H2 数据库自动创建

我通过 Spring Boot 在我的 Java 应用程序中使用嵌入式 H2。目前,它在数据库中创建(覆盖)我的表。但是,一旦我将其投入生产,我不希望我的表被擦除并重新创建,因此我不会丢失表中以前的数据。但我不知道如何实现这一点。不知道该放什么就行了 spring.jpa.hibernate.ddl-auto=create。我尝试了验证和其他选项,但没有成功。这是我的 application.properties。谢谢

spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true
spring.datasource.initialization-mode=always
spring.jpa.hibernate.naming.physical- 
strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Run Code Online (Sandbox Code Playgroud)

java spring hibernate h2 spring-boot

4
推荐指数
2
解决办法
4万
查看次数

从 Spring Boot 获取与 H2 数据库的连接

我正在使用 Spring Boot、H2 和 JPA 作为我的数据库,我可以通过将连接属性放入application.properties. 但我不知道如何使用Spring Boot为我建立的连接。

在下面的代码中,我可以使用conn运行语句等。

   static final String JDBC_DRIVER = "org.h2.Driver";   
   static final String DB_URL = "jdbc:h2:~/test";
   static final String USER = "sa"; 
   static final String PASS = ""; 

Connection conn = null; 
  Statement stmt = null; 
  try { 

     Class.forName(JDBC_DRIVER); 
     conn = DriverManager.getConnection(DB_URL,USER,PASS);  
    //This is what I want to do with spring as I obtain a conn variable and use it.
     stmt = conn.createStatement(); 
     String sql =  "CREATE TABLE   REGISTRATION " + …
Run Code Online (Sandbox Code Playgroud)

java jdbc h2 spring-jdbc spring-boot

3
推荐指数
1
解决办法
6980
查看次数

标签 统计

h2 ×2

java ×2

spring-boot ×2

hibernate ×1

jdbc ×1

spring ×1

spring-jdbc ×1