Hello Alex,
I am getting error code: 90030.
Please find attached code which I have tried in java using
org.h2.tools.Recover.
Please find attached code snippet and error message on console. However,
our database in not encrypted.
Please suggest what can be done.
On Saturday, August 24, 2024 at 3:04:36 PM UTC+5:30 Alex Tsvetkov wrote:
> Hi.
>
> What error message do you get exactly?
>
> Easiest way to troubleshoot this will be to use debugger, but it only
> works if you familiar with the tool.
>
> четверг, 22 августа 2024 г. в 16:52:31 UTC+3, prachi sugdare:
>
>> Hello Team,
>>
>> I have one .mv.db file which is corrupted. I am using following command
>> to recover the file, however it is showing error message.
>>
>> java -cp h2-1.4.200.jar org.h2.tools.Recover -dir "C:/corrupted" -db
>> "asms_corrupted" -out "C:/recover/asms2_local_DB.mv"
>>
>> Please suggest what can be done to recover the same file.
>>
>> Thanks & Regards,
>> Prachi More.
>>
>
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/h2-database/cf7d2074-804f-471f-b9e3-98588f6421dfn%40googlegroups.com.
package com.bv;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.tools.Recover;
public class H2DatabaseExample {
public static void main(String[] args) {
// Original database URL and recovery URL
String jdbcUrl = "jdbc:h2:C:\\corrupted\\asms_corrupted";
String recoveryFilePath = "C:\\recover";
// Database credentials
String username = "dba";
String password = "sql";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
// Register JDBC driver
Class.forName("org.h2.Driver");
// Open a connection
conn = DriverManager.getConnection(jdbcUrl, username, password);
} catch (SQLException e) {
// Handle SQL exceptions and check if the database is corrupted
if (e.getSQLState().startsWith("90030")) { // 08006 is a common SQLState for connection issues, including corruption
System.out.println("Database corruption detected. Attempting recovery...");
try {
// Use H2 Recover tool to recover the database
Recover.main(new String[]{
"-dir", "C:/corrupted",
"-db", "asms_corrupted",
"-out", recoveryFilePath,
// "-password", "sql"
});
System.out.println("Database recovery completed. Please check the recovery location.");
} catch (Exception recoverException) {
System.out.println("Recovery failed: " + recoverException.getMessage());
}
} else {
System.out.println("SQL Exception: " + e.getMessage());
}
} catch (Exception e) {
// Handle other exceptions
System.out.println("Exception: " + e.getMessage());
} finally {
// Clean-up environment
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
}
}