[solved] Will not persist to my jdbc mariadb database!

  • Platform information:
    • Hardware: QNAP
    • OS: Linux
    • Java Runtime Environment: not sure
    • openHAB version:2.2.0 (release build)

I am trying to setup persistence. I have got reasonably far, but am not stuck. My installation will:

  • turn on and off a light
  • has a mariadb database
  • I have manually created the openhab database schema
  • configuration to connect to the database and log every single event change
  • openhab has created a single ‘items’ table in the schema. This currently has two columns: ItemId and itemname. (Is this correct?)

What could be wrong?

Many thanks, George

My first config file is jbdc.persist

// persistence strategies have a name and definition and are referred to in the "Items" section
Strategies {
        everyHour : "0 0 * * * ?"
        everyDay  : "0 0 0 * * ?"

        // if no strategy is specified for an Item entry below, the default list will be used
       default = everyChange
}

/*
 * Each line in this section defines for which Item(s) which strategy(ies) should be applied.
 * You can list single items, use "*" for all items or "groupitem*" for all members of a group
 * Item (excl. the group Item itself).
 */
 
 
Items {
        // persist the Item state of Heating_Mode and Notifications_Active on every change and restore them from the db at startup
        Heating_Mode, Notifications_Active: strategy = everyChange, restoreOnStartup

        // additionally, persist all temperature and weather values every hour
		* : strategy = everyChange, everyDay, restoreOnStartup
        Energyswitch1_Power, Energyswitch2_Power : strategy = everyChange, everyDay, restoreOnStartup
		F2_Loft_Light : strategy = everyChange, everyDay, restoreOnStartup
}

My second config file is jbdc.cfg. I am only including the non-commented out lines.

url=jdbc:mariadb://192.168.0.15:3306/openhab
# required database user
user=root

# required database password
password=admin

The logs are showing it is connecting to the database.


2019-05-11 20:40:44.579 [INFO ] [persistence.jdbc.internal.JdbcMapper] - JDBC::openConnection: Driver is available::Yank setupDataSource
2019-05-11 20:40:45.842 [INFO ] [persistence.jdbc.internal.JdbcMapper] - JDBC::logTime: 'pingDB':
 afterAccess     = 1259 ms
 timeAverage50  = 1259 ms
 timeAverage100 = 1259 ms
 timeAverage200 = 1259 ms
 afterAccessMin  = 1259 ms
 afterAccessMax  = 1259 ms
 1000Statements = 0 sec
 statementCount = 1

2019-05-11 20:40:45.917 [INFO ] [persistence.jdbc.internal.JdbcMapper] - JDBC::logTime: 'doCreateItemsTableIfNot':
 afterAccess     = 49 ms
 timeAverage50  = 654 ms
 timeAverage100 = 654 ms
 timeAverage200 = 654 ms
 afterAccessMin  = 49 ms
 afterAccessMax  = 1259 ms
 1000Statements = 0 sec
 statementCount = 2

2019-05-11 20:40:45.937 [INFO ] [persistence.jdbc.internal.JdbcMapper] - JDBC::logTime: 'getItemIDTableNames':
 afterAccess     = 16 ms
 timeAverage50  = 441 ms
 timeAverage100 = 441 ms
 timeAverage200 = 441 ms
 afterAccessMin  = 16 ms
 afterAccessMax  = 1259 ms
 1000Statements = 0 sec
 statementCount = 3

Are you sure about the filename? Because the file has to be named
jdbc.persist, not jbdc.persist
Same for config file, has to be
jdbc.cfg, not jbdc.cfg

Thank you very much. No idea how I missed that! I have changed the file names and restarted the openhab service, and now records are appearing.

PS I would love to mark this as ‘solved’ but I cannot figure out how to.

There should be a checkbox under each posting (maybe within “…” menu)
Please also change the headline of the first posting to [solved]...