<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: cannot use DB connect app with H2 database in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/cannot-use-DB-connect-app-with-H2-database/m-p/191618#M73016</link>
    <description>&lt;P&gt;Thank you, sigi.&lt;/P&gt;

&lt;P&gt;I end up with using H2 AUTO_SERVER mode.&lt;BR /&gt;
In the grails project, I set jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;AUTO_SERVER=TRUE&lt;/P&gt;

&lt;P&gt;Then use the same in the Splunk DB Connect.&lt;/P&gt;

&lt;P&gt;By doing so, H2 will use in-process call for Grails webapp, and use a tcp port for DB connect to read data.&lt;/P&gt;

&lt;P&gt;In my project, the Grails app will generate log and also create/update data in H2. I'd like to create splunk dashboard to show data from log and database. So copying the H2 database to somewhere else is not an option.&lt;/P&gt;

&lt;P&gt;After checking database_types.conf.spec, I know how to set JDBC string. Thx.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 15:34:54 GMT</pubDate>
    <dc:creator>jzhong_splunk</dc:creator>
    <dc:date>2020-09-28T15:34:54Z</dc:date>
    <item>
      <title>cannot use DB connect app with H2 database</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/cannot-use-DB-connect-app-with-H2-database/m-p/191615#M73013</link>
      <description>&lt;P&gt;I tried to use DB Connect to get data from H2 database.&lt;/P&gt;

&lt;P&gt;My H2 database files are at&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/usr/share/tomcat7/prodDb.h2.db
/usr/share/tomcat7/prodDb.h2.db.bak
/usr/share/tomcat7/prodDb.lock.db
/usr/share/tomcat7/prodDb.trace.db
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(This database is automatically created by Grails framework for Java)&lt;/P&gt;

&lt;P&gt;I cannot use DB Connect app to connect to this existing database. Instead, it has problem to locate the database.&lt;/P&gt;

&lt;P&gt;The correct JDBC connection string should be "jdbc:h2:/usr/share/tomcat7/prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000"&lt;/P&gt;

&lt;P&gt;But DB Connect doesn't allow me to set the full JDBC string. Instead, it asks me about the database file.&lt;/P&gt;

&lt;P&gt;If I set /usr/share/tomcat7/prodDb, then it will create folder at /opt/splunk/var/dbx/usr/share/tomcat7/prodDb.h2&lt;/P&gt;

&lt;P&gt;Damn! In the web page, it reads &lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;"You can either specify the absolute&lt;BR /&gt;
path to the database or place it under&lt;BR /&gt;
$SPLUNK_HOME/var/dbx/&lt;NAME&gt;.h2".&lt;/NAME&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;It seems that the absolute path doesn't really work.&lt;/P&gt;

&lt;P&gt;Then I tried to use relative path:&lt;BR /&gt;
../../../../usr/share/tomcat7/prodDb.h2&lt;/P&gt;

&lt;P&gt;Then DB connect will create folder ../../../../usr/share/tomcat7/prodDb.h2/db&lt;/P&gt;

&lt;P&gt;This drives me crazy. Then I have to decompile the dbx.jar to see what kind of code logic it uses.&lt;/P&gt;

&lt;P&gt;in dbx.jar/com.splunk.dbx.sql.type.impl.H2&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  public java.sql.Connection connect(String host, int port, String username, String password, String database, java.util.Map params, com.splunk.config.SplunkConfigStanza configStanza) throws java.sql.SQLException {
    return connect(host, port, "sa", "", database, params, configStanza);
  }

  public String getConnectionString(String host, int port, String database, java.util.Map params) {
    return String.format("jdbc:h2:%s;database_to_upper=false", {getDatabasePath(database)};);
  }

  private String getDatabasePath(String database) {
    java.io.File parentDir;
    parentDir = com.splunk.env.SplunkContext.getEnvironment().getSplunkPath(0, 1, {"var","dbx",String.format("%s.h2", {database};)};);
    return new java.io.File(parentDir, "db").getAbsolutePath();
  }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;According to this code. DB connect will also connect H2 with user "sa", and JDBC path with template jdbc:h2:%s;database_to_upper=false. For the database, it always use %SPLUNK/var/dbx/%db%, and automatically created folder, %db.h2/db.&lt;/P&gt;

&lt;P&gt;I would suggest the DB connect team just opens a JDBC string for us to specify. Don't be too smart.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:33:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/cannot-use-DB-connect-app-with-H2-database/m-p/191615#M73013</guid>
      <dc:creator>jzhong_splunk</dc:creator>
      <dc:date>2020-09-28T15:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: cannot use DB connect app with H2 database</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/cannot-use-DB-connect-app-with-H2-database/m-p/191616#M73014</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;you should be able to specify anything by editing the configuration file directly; would that work better for you?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2014 01:01:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/cannot-use-DB-connect-app-with-H2-database/m-p/191616#M73014</guid>
      <dc:creator>jcoates_splunk</dc:creator>
      <dc:date>2014-01-01T01:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: cannot use DB connect app with H2 database</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/cannot-use-DB-connect-app-with-H2-database/m-p/191617#M73015</link>
      <description>&lt;P&gt;I'd generally advice against accessing a H2 db via the filesystem from multiple processes. The safest way would be to copy over the database files into a folder &lt;CODE&gt;$SPLUNK_HOME/var/dbx/&amp;lt;dbname&amp;gt;.h2&lt;/CODE&gt; or to enable the server mode of H2 in the host application and add a new database type to connect to it via TCP.&lt;/P&gt;

&lt;P&gt;For the server approach see &lt;A href="http://www.h2database.com/html/tutorial.html#using_server"&gt;http://www.h2database.com/html/tutorial.html#using_server&lt;/A&gt; on how to start the TCP server of H2. Here's an example of a new database type definition that should work for connecting to such a server:&lt;/P&gt;

&lt;P&gt;database_types.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[h2tcp]
displayName = H2 (TCP Server)
jdbcDriverClass = org.h2.Driver
connectionUrlFormat = jdbc:h2:tcp://{0}/{1}
testQuery = SELECT 1
defaultSchema = PUBLIC
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It's also possible to add a custom database type for connecting to an H2 db located at an arbitrary path (again, not recommend if multiple processes are accessing the same files):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[h2abs]
displayName = H2 (absolute path)
jdbcDriverClass = org.h2.Driver
connectionUrlFormat = jdbc:h2:{1};MVCC=TRUE;LOCK_TIMEOUT=10000
testQuery = SELECT 1
defaultSchema = PUBLIC
local = true
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Jan 2014 17:58:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/cannot-use-DB-connect-app-with-H2-database/m-p/191617#M73015</guid>
      <dc:creator>ziegfried</dc:creator>
      <dc:date>2014-01-03T17:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: cannot use DB connect app with H2 database</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/cannot-use-DB-connect-app-with-H2-database/m-p/191618#M73016</link>
      <description>&lt;P&gt;Thank you, sigi.&lt;/P&gt;

&lt;P&gt;I end up with using H2 AUTO_SERVER mode.&lt;BR /&gt;
In the grails project, I set jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;AUTO_SERVER=TRUE&lt;/P&gt;

&lt;P&gt;Then use the same in the Splunk DB Connect.&lt;/P&gt;

&lt;P&gt;By doing so, H2 will use in-process call for Grails webapp, and use a tcp port for DB connect to read data.&lt;/P&gt;

&lt;P&gt;In my project, the Grails app will generate log and also create/update data in H2. I'd like to create splunk dashboard to show data from log and database. So copying the H2 database to somewhere else is not an option.&lt;/P&gt;

&lt;P&gt;After checking database_types.conf.spec, I know how to set JDBC string. Thx.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:34:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/cannot-use-DB-connect-app-with-H2-database/m-p/191618#M73016</guid>
      <dc:creator>jzhong_splunk</dc:creator>
      <dc:date>2020-09-28T15:34:54Z</dc:date>
    </item>
  </channel>
</rss>

