JDBC Not working on ESH

Hello,

I am trying to save item states values into DB.

I have been used openhab compatibility layer and org.openhab.persistence.jdbc bindings and sqlite-jdbc-3.21.0 driver , it’s being in ACTIVE.

Here openhab compatibility and org.openhab.persistence.jdbc and sqlite-jdbc-3.21.0 jar files added to deplay folder in ESH repo.

According to openhab official documentation to configured below jdbc related files.

openhab.cfg file

############################ SQL Persistence Service ##################################
# the database url like 'jdbc:mysql://<host>:<port>/<database>' (without quotes)
mysql:url=jdbc:sqlite:./testSqlite.db

# the database user
mysql:user=TEST

# the database password
mysql:password=TEST

# the reconnection counter
#mysql:reconnectCnt=

# the connection timeout (in seconds)
#mysql:waitTimeout=

# Use MySQL Server time to store item values (=false) or use openHAB Server time (=true).
# For new installations, its recommend to set "mysql:localtime=true".
# (optional, defaults to false)
#mysql:localtime=true

jdbc.cfg file

############################ JDBC Persistence Service ##################################
# I N S T A L L   J D B C   P E R S I S T E N C E   S E R V I C E 
#
# https://github.com/openhab/openhab/wiki/JDBC-Persistence
#
# Tested databases/url-prefix: jdbc:derby, jdbc:h2, jdbc:hsqldb, jdbc:mariadb, jdbc:mysql, jdbc:postgresql, jdbc:sqlite
# 
# derby, h2, hsqldb, sqlite can be embedded, 
# If no database is available it will be created, for example the url 'jdbc:h2:./testH2' creates a new DB in OpenHab Folder. 
#
# Create new database, for example on a MySQL-Server use: 
# CREATE DATABASE 'yourDB' CHARACTER SET utf8 COLLATE utf8_general_ci;

# D A T A B A S E  C O N F I G
# Some URL-Examples, 'service' identifies and activates internally the correct jdbc driver.
# required database url like 'jdbc:<service>:<host>[:<port>;<attributes>]'
# url=jdbc:derby:./testDerby;create=true
# url=jdbc:h2:./testH2
# url=jdbc:hsqldb:./testHsqlDb
# url=jdbc:mariadb://192.168.0.1:3306/testMariadb
# url=jdbc:mysql://192.168.0.1:3306/testMysql
# url=jdbc:postgresql://192.168.0.1:5432/testPostgresql
# url=jdbc:sqlite:./testSqlite.db
# url=

url=jdbc:sqlite:./database/openhab.db

# required database user

user=TEST

# required database password

password=TEST

# E R R O R   H A N D L I N G
# optional when Service is deactivated (optional, default: 0 -> ignore) 

errReconnectThreshold=0

# I T E M   O P E R A T I O N S
# optional tweaking SQL datatypes
# see: https://mybatis.github.io/mybatis-3/apidocs/reference/org/apache/ibatis/type/JdbcType.html   
# see: http://www.h2database.com/html/datatypes.html
# see: http://www.postgresql.org/docs/9.3/static/datatype.html
# defaults:
sqltype.CALL          =   VARCHAR(200)
sqltype.COLOR         =   VARCHAR(70)
sqltype.CONTACT       =   VARCHAR(6)
sqltype.DATETIME      =   DATETIME
sqltype.DIMMER        =   TINYINT
sqltype.LOCATION      =   VARCHAR(30)
sqltype.NUMBER        =   DOUBLE
sqltype.ROLLERSHUTTER =   TINYINT
sqltype.STRING        =   VARCHAR(65500)
sqltype.SWITCH        =   VARCHAR(6)

# For Itemtype "Number" default decimal digit count (optional, default: 3) 

numberDecimalcount=3

# T A B L E   O P E R A T I O N S
# Tablename Prefix String (optional, default: "item") 
# for Migration from MYSQL-Bundle set to 'Item'.

tableNamePrefix=Item

# Tablename Prefix generation, using Item real names or "item" (optional, default: false -> "item") 
# If true, 'tableNamePrefix' is ignored.

tableUseRealItemNames=false

# Tablename Suffix length (optional, default: 4 -> 0001-9999) 
# for Migration from MYSQL-Bundle set to 0.

tableIdDigitCount=4

# Rename existing Tables using tableUseRealItemNames and tableIdDigitCount (optional, default: false) 
# USE WITH CARE! Deactivate after Renaming is done!

rebuildTableNames=false

# D A T A B A S E  C O N N E C T I O N S
# Some embeded Databases can handle only one Connection (optional, default: configured per database in packet org.openhab.persistence.jdbc.db.* )
# see: https://github.com/brettwooldridge/HikariCP/issues/256
# jdbc.maximumPoolSize = 1
# jdbc.minimumIdle = 1

# T I M E K E E P I N G
# (optional, default: false) 

enableLogTime=false

jdbc.persist file

Strategies {
	everyHour : "0 0 * * * ?"
	everyDay  : "0 0 0 * * ?"


	default = everyChange
}


Items {
	// persist all items once a day and on every change and restore them from the db at startup
	* : strategy = everyChange, everyDay, restoreOnStartup
	
	
}

When I was trying to store item states values into DB…it’s showing some below

17:22:20.124 INFO [safeCall-1] Item 'light2' received command ON
17:22:20.128 INFO [safeCall-2] light2 changed from NULL to ON
17:22:20.128 INFO [safeCall-3] light2 updated to ON
17:22:20.124 DEBUG [items-1] JDBC::pingDB
17:22:20.148 DEBUG [items-1] JDBC::openConnection isDriverAvailable: false
17:22:20.160 WARN [items-1] JDBC::openConnection: no driver available!
17:22:20.160 DEBUG [items-1] JDBC::pingDB
17:22:20.168 DEBUG [items-1] JDBC::openConnection isDriverAvailable: false
17:22:20.174 WARN [items-1] JDBC::openConnection: no driver available!
17:22:20.177 DEBUG [items-1] JDBC::checkDBAcessability, second try connection: false
17:22:20.177 WARN [items-1] JDBC::store:  No connection to database. Cannot persist item 'light2 (Type=SwitchItem, State=ON)'! Will retry connecting to database when error count:0 equals errReconnectThreshold:0

What I did mistake in configurations and setup. I am new to use jdbc in home automation.
Please help me how i can store item states into DB.

Thanks and Regards

Amar.

I think you’re using the wrong config files.

According to the docs, to use mysql for persistence, you need to use the files mysql.cfg and mysql.persist.