0

So, after searching Google and Github for answers, I'm left confounded as to how most people know how to use HikariCP. I can't seem to find any straight up documentation on HikariCP.

My question is: how do I specify the host address without a JDBC URL? The main page of HikariCP on Github clearly says that JDBC URL specification is optional and instead to simply use HikariConfig#setDataSourceClassName(String). However, I'm confused then as to how I would specify my address and I can't seem to find the answer anywhere. Like with SQLite, where do I specify the path to where the database file should go?

This is the code I currently have:

final HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setPoolName("SQLite");
hikariConfig.setDataSourceClassName("org.sqlite.SQLiteDataSource");

HikariDataSource ds = new HikariDataSource(hikariConfig);

If I was to not use HikariCP I would simply specify the JDBC URL like such: jdbc:sqlite:path/to/database.db. However, how do you do this without using a JDBC URL?

Thanks for any help.

Andavin
  • 41
  • 6
  • That page you link to **is the documentation**, that and the wiki that is also linked from that page. However your question is unclear, seems to ask for external resources and is also too broad, because besides asking how to use it at all with SQLite, you immediately jump to asking about performance tips, etc. Please edit your question to focus on one specific question, and for example show what you'd do to configure your connection **without** HikariCP. – Mark Rotteveel Aug 17 '17 at 09:57
  • Thank you for the tips. This is my first question on StackOverflow and I was trying to get all my concerns answered. In the case of my link **being the documentation** it seems that it is relatively lacking; although the question below kind of tells me that I need to know more about the specific driver. – Andavin Aug 17 '17 at 20:36
  • You should not try to get everything into one question, focussed questions on a single issue will get better answers. As to the documentation, HikariCP has great documentation (or at least I have seen worse), it simply can't address everything, especially not if it comes to how stuff from other drivers needs to be configured. – Mark Rotteveel Aug 18 '17 at 06:26
  • Haha yes, I now realize I should only ask pointed questions more instead of several. Also, what I meant by _relatively lacking_ was that most of the documentation is left up to the driver itself. I now do realize that I should be looking at the specific driver documentation. Thank you for all the help :) – Andavin Aug 18 '17 at 07:14

1 Answers1

1

When you use DataSource-style instead of URL-style configuration, all datasource properties translate to setters on the DataSource class. So, since you seem to be using the org.sqlite.SQLiteDataSource, the various setters on that class are what is relevant.

Here is an example of setting not only the URL of the DataSource, but also setting the Journal Mode and enabling full column name support.

final HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setPoolName("SQLite");
hikariConfig.setDataSourceClassName("org.sqlite.SQLiteDataSource");
hikariConfig.addDataSourceProperty("url", "jdbc:sqlite:C:/work/mydatabase.db");
hikariConfig.addDataSourceProperty("journalMode", "WAL");
hikariConfig.addDataSourceProperty("fullColumnNames", "true");

HikariDataSource ds = new HikariDataSource(hikariConfig);

This reason DataSource-style is preferable is two-fold:

  • The use of reflection ensures that any typo in a property name causes a failure. Whereas, properties with typos specified in the JDBC URL itself are typically ignored by drivers.
  • When there are a large number of properties specified, a JDBC URL connection string can get extremely long -- several hundred characters for some drivers -- which makes reading/understanding what properties are actually set extremely cumbersome.
brettw
  • 10,664
  • 2
  • 42
  • 59
  • So I do need to specify a sort of JDBC URL just not adding the properties to it simply the address. Thank you for the answer; it actually thoroughly answered all my questions even if it wasn't meant to. – Andavin Aug 17 '17 at 20:37
  • 1
    Some driver have setters like databaseName, host, port, etc. instead of a URL. SQLite does not. It all depends on the DataSource implementation. – brettw Aug 18 '17 at 00:45