Tuesday, March 17, 2015

How to see the H2 database content in a WSO2 Product

Every WSO2 product comes with an embedded H2 database as the default database configuration. There can be times we need to see the content of this database.

In this post, I'm going to explain how to see this database content through the H2 console.

First you have to configure the following in the <product-home>/repository/conf/carbon.xml file.

        
        8082
        
 
Once the configuration done as above, start the server(wso2 product you want).

Then open a browser and goto "http://localhost:8082/". You can see the login page as follows.



You need to give the JDBC URL, username and password.

You can find the relevant JDBC URL in the <product-home>/repository/conf/datasources/master-datasources.xml

For example, in ML, it is given as follows;

    WSO2ML_DB
    The datasource used for Machine Learner database
    
        jdbc/WSO2ML_DB
    
    
        
            jdbc:h2:repository/database/WSO2ML_DB;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000
            wso2carbon
            wso2carbon
            org.h2.Driver
            50
            60000
            true
            SELECT 1
            30000
        
    

Copy the url given in the element. Here it is jdbc:h2:repository/database/WSO2ML_DB.

Give the username and password given in the and elements in the above configuration. (The default username and password comes with every wso2 product is admin, admin)

You will see the H2 console like this.



Note :

When you need to do some change in the database of a wso2 product and setup the server with that change, you have to run the startup script as follows.

./wso2server.sh -Dsetup

Note that, in order to apply the changes first you have to delete the contents in the directory <product-home>/repository/database. Then start the server with -Dsetup option.

No comments: