H2 database control: Difference between revisions
imported>Kymara No edit summary |
imported>AntumDeluge →Connecting to the H2 Database: side-by-side connections |
||
| (17 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
== |
== Connecting to the H2 Database == |
||
<del> |
|||
Make sure the game server is '''not running''' (using '''CTRL+c''' at the server command window). Otherwise you'll get this error later: |
Make sure the game server is '''not running''' (using '''CTRL+c''' at the server command window). Otherwise you'll get this error later: |
||
[[File:H2dbGuide001.png]] |
[[File:H2dbGuide001.png]] |
||
</del> |
|||
In order to access the database while server is running, "AUTO_SERVER=TRUE" must be added to the "jdbc_url" line in <code>server.ini</code>. |
|||
Open a command window as explained above. |
Open a command window as explained above. |
||
| Line 13: | Line 17: | ||
[[File:H2dbGuide002.png]] |
[[File:H2dbGuide002.png]] |
||
Alternatively, you can see it with any other web browser by entering the following URL: |
'''Alternatively,''' you can see it with any other web browser by entering the following URL: |
||
http://localhost:8082/ |
http://localhost:8082/ |
||
Don't connect yet as you need to set the ... |
|||
===Configuration parameters=== |
|||
At the ''URL JDBC:'' text field, copy and paste this: |
At the ''URL JDBC:'' text field, copy and paste this: |
||
| Line 35: | Line 42: | ||
Now you should have been given access to the game database. |
Now you should have been given access to the game database. |
||
==Exploring the H2 database== |
|||
For starters, you can see the accounts in the database by clicking on the ACCOUNT table name on the left graphical tree: |
For starters, you can see the accounts in the database by clicking on the ACCOUNT table name on the left graphical tree: |
||
| Line 53: | Line 61: | ||
Feel free to experiment from here on. :) Anything other than a SELECT should be used with caution on production environments! |
Feel free to experiment from here on. :) Anything other than a SELECT should be used with caution on production environments! |
||
| ⚫ | |||
== Stop the H2 database == |
|||
To stop the database engine use the same method as with the game server: type '''CTRL+c''' at the command window. |
To stop the database engine use the same method as with the game server: type '''CTRL+c''' at the command window. |
||
== Backup the H2 database == |
|||
| ⚫ | |||
You can copy the files in ~/stendhal/database but the server must be '''stopped'''. |
|||
Otherwise from within the h2 environment, as above, use command |
|||
BACKUP to 'file.zip' |
|||
Latest revision as of 02:46, 24 June 2022
Connecting to the H2 Database
Make sure the game server is not running (using CTRL+c at the server command window). Otherwise you'll get this error later:
In order to access the database while server is running, "AUTO_SERVER=TRUE" must be added to the "jdbc_url" line in server.ini.
Open a command window as explained above. Use cd (change directory) to get to the server's folder (where a file named h2.jar should exist) and copy and paste this:
java -cp h2*.jar org.h2.tools.Server
You'll notice that your default browser automatically opens, showing a page that offers access to databases:
Alternatively, you can see it with any other web browser by entering the following URL:
http://localhost:8082/
Don't connect yet as you need to set the ...
Configuration parameters
At the URL JDBC: text field, copy and paste this:
jdbc:h2:~/stendhal/database/h2db
Note (if your server files are not in ~/stendhal): By default, the server.ini configuration file defines the H2 database directory as "~/stendhal/database/". Unless, you have edited the server.ini file, this is where your database resides regardless of from what directory you are running the server.
Make sure the Username and Password fields are empty:
and click on the [Connect] button:
Now you should have been given access to the game database.
Exploring the H2 database
For starters, you can see the accounts in the database by clicking on the ACCOUNT table name on the left graphical tree:
You'll notice that in the SQL instruction text box at the right:
a new SQL statement has automatically appeared:
Now, just click on the [Execute] button (or alternatively type CTRL+Enter) and you can see the results of the SQL statement just below the 'SQL instruction' text box:
Feel free to experiment from here on. :) Anything other than a SELECT should be used with caution on production environments!
For a list of H2 commands see http://www.h2database.com/html/grammar.html
Stop the H2 database
To stop the database engine use the same method as with the game server: type CTRL+c at the command window.
Backup the H2 database
You can copy the files in ~/stendhal/database but the server must be stopped. Otherwise from within the h2 environment, as above, use command
BACKUP to 'file.zip'





