SQL query in H2 database table throws ArrayIndexOutOfBoundsException

I have an H2 database that some queries are running on while others throw an ArrayIndexOutOfBoundsException .

For instance:

 SELECT COLUMN_1 FROM MY_TABLE; // works fine SELECT COUNT(COLUMN_1) FROM MY_TABLE; // gives following error message: [Error Code: 50000, SQL State: HY000] General error: "java.lang.ArrayIndexOutOfBoundsException"; SQL statement: SELECT COUNT(COLUMN_1) FROM MY_TABLE [50000-167] 

What is the reason for this eror post?

+6
source share
1 answer

The cause of the error message was a damaged database.

I solved the problem using the H2 recovery tool. . The steps were as follows:

  • Create recovery script

     C:\PATH_TO_CORRUPT_DB>java -cp C:\PATH_TO_MY_H2\h2.jar org.h2.tools.Recover 
  • Delete the old db file (of course, without creating a backup;))

  • Restore database

     C:\PATH_TO_CORRUPT_DB>java -cp C:\PATH_TO_MY_H2\h2.jar org.h2.tools.RunScript -url jdbc:h2:PATH_TO_CORRUPT_DB\NAME_OF_DB -script NAME_OF_SCRIPT_FROM_STEP_ONE.sql 


Here you can find a more detailed description of using H2 Recovery Tool

+4
source

Source: https://habr.com/ru/post/974160/


All Articles