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
If you are dealing with the Spring Boot project, please change the JDBC URL jdbc:h2:~/test
to jdbc:h2:mem:testdb
in the login page, which is the default URL configured by Spring Boot.
enter image description here
Maven dependency
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.193</version>
</dependency>
</dependencies>
MacOS Catalina 10.15.4 Worked!
Problem:
Database not found or test folder not in c:/user/username/test
Copy&paste it in application.properties file:
spring.datasource.url=jdbc:h2:~/test
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
Issue was of URL, check it. Problem solved.
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);
I also got this Error. You have to Configured
*application.properties*
# temporary data storage
spring.datasource.url = jdbc:h2:file:C:/data/test (Windows only)
spring.h2.console.path=/h2
server.port=8181
You have to create Folder in C: Drive data/test
Go To Browser:
http://localhost:8181/h2
Then URL:
jdbc:h2:file:C:/data/test
You Can See in this pic also: [1]
[1]: https://i.stack.imgur.com/ExFNR.png
You can see youtube Video
https://youtu.be/yYWPuM8k8K4
Have you upgraded H2 recently? This could be the cause.
This is related to the following H2 commit:
https://github.com/h2database/h2database/commit/8b53f3999c6c5c3d5ca29020e2657968f4f59ec4
and the change was made because of this exploit:
https://www.exploit-db.com/exploits/45506
This means that the default for H2 is now to not auto-create databases when run in standalone network mode.
If you have read and understood the above, and you still want to allow the database to be auto-created, then just add the -ifNotExists
flag to your h2 start command like this:
java -cp h2*.jar org.h2.tools.Server -ifNotExists