loading db credentials from liferay-ext-properties - strange problemloading db credentials from liferay-ext-properties - strange problemhttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1187515912024-03-28T11:38:45Z2024-03-28T11:38:45Zloading db credentials from liferay-ext-properties - strange problemBartosz Sochahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1187515902020-12-04T16:52:25Z2020-03-16T17:26:05Z<html><head></head><body>Hello,<br>I want to import db credentials from liferay-ext-properties file to establish jdbc connection and execute few queries.<br>Unfortunately I am facing strange situation.<br>When I hardcode those credentials inside my external module (which implements BundleActivator) everything is fine.<br><br>But when I decide to swap below lines (original):<br> private final String dbUrl = "jdbc:postgresql://localhost:5432/dbtest";<br> private final String dbLogin = "test";<br> private final String dbPass = "test";<br> private final String dbDriver = "org.postgresql.Driver";<br>for those ones:<br> private final String dbUrl = PropsUtil.get("jdbc.default.url");<br> private final String dbLogin = PropsUtil.get("jdbc.default.username");<br> private final String dbPass = PropsUtil.get("jdbc.default.password");<br> private final String dbDriver = PropsUtil.get("jdbc.default.driverClassName");<br>with following content of properties file:<br>jdbc.default.driverClassName=org.postgresql.Driver<br>jdbc.default.password=test<br>jdbc.default.url=jdbc:postgresql://localhost:5432/dbtest<br>jdbc.default.username=test<br>It results in exception ClassNotFoundException, org.postgresql.Driver not found. Inside a program debugger, I can obviously see that String content is exactly the same (content of properties is correctly loaded to the same variables as before), but for some non clear reasons driver is not loaded. I tried to add dependency of postgres in pom file (which I didn't have before this problem occured) with good version and different scopes, but result is the same. When I come back to original version without restarting tomcat, everything works again correctly.<br>I am using old plain JDBC and the exception is being thrown on line:<br><pre><code>
</code></pre> Class.forName(dbDriver).newInstance();<br>Any hints? Does call PropsUtil.get do something implicit which I am not waware about ? I paid attention for blank spaces in String and I am sure that String content is exactly the same. I also tried to replace Class.forName(dbDriver).newInstance() with Class.forName(dbDriver).</body><