I'm doing a simple API, and i'm getting the next error:
File corrupted while reading record: null. Possible solution: use the recovery tool [90030-200]
this is the code of the controller that i'm using
@PostMapping("/save")
public ResponseEntity saveDentist(@RequestBody Dentist data) {
DentistService dentistService = new DentistService(new DentistDaoH2());
if(data == null) {
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
return ResponseEntity.status(200).body(dentistService.save(data));
}
this is the code of the DAO for the operations of the database(i'm using H2):
@Override
public Dentist save(Dentist data) {
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
Class.forName(JDBC_DRIVER_H2);
connection = DriverManager.getConnection(URL,USER,PASSWORD);
preparedStatement = connection.prepareStatement("INSERT INTO dentist values(?,?,?,?)");
preparedStatement.setString(1,data.getName());
preparedStatement.setString(2,data.getLastName());
preparedStatement.setInt(3,data.getAge());
preparedStatement.setString(4,data.getProfessionalCard());
preparedStatement.executeUpdate();
preparedStatement.close();
System.out.println("its saved");
logger.info("the user was registered with success");
} catch (SQLException e) {
logger.error(e.getMessage());
} catch (ClassNotFoundException e) {
e.printStackTrace();
logger.error(e.getMessage());
}
return data;
}
the code of the service:
public Dentist save(Dentist dentist) {
if(dentist == null) {
return null;
}
return this.daoService.save(dentist);
}
the repository layer have the next configuration for h2:
private static final String JDBC_DRIVER_H2 = "org.h2.Driver";
private final static String USER = "sa";
private final static String PASSWORD = "";
private final static String URL = "jdbc:h2:~/test";
In the file application.properties have :
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
spring.h2.console.enabled = true
CodePudding user response:
Check this link for a solution Database Panel: Only outdated JDBC driver versions available for H2
CodePudding user response:
This indicates that your database has become corrupted. It's more difficult to pinpoint why it was tampered with.
The Recover programme will do its best, but there isn't always much it can do when the database is severely corrupted.
The Recovery tool's documentation can be found here:
http://h2database.com/html/advanced.html#using_recover_tool
And you can also visit here: https://ubooquity.userecho.com/en/communities/1/topics/922-recovering-database-with-error-file-corrupted-while-reading-record-null