Example 1. using the getClass().getResource("/images/logo.png") construct. Since the name starts with the character '/', it is considered absolute. Search for a resource is as follows:
The resource name /images/logo.png assigned to the path from the classpath c:\work\myproject\classes , as a result of which the file c:\work\myproject\classes\images\logo.png is searched. If the file is found, the search is terminated. Otherwise: In the jar file c:\lib\lib.jar the file c:\lib\lib.jar is searched, and the search is conducted from the root of the jar file.
Example 2. We use the getClass().getResource("res/data.txt") construct. Since the name does not begin with the character '/', it is considered relative. Search for a resource is as follows:
The path from the classpath c:\work\myproject\classes assigned the current class package, where the code is located, /ru/skipy/test , and then the resource name res/data.txt , which results in a file c:\work\myproject\classes\ru\skipy\test\res\data.txt . If the file is found, the search is terminated. Otherwise: In the jar file c:\lib\lib.jar the file /ru/skipy/test/res/data.txt (the name of the package of the current class plus the name of the resource) is searched for, and the search is conducted from the root of the jar-file.
In your case, you need to write getResourceAsStream("db.properties") without specifying the '/' symbol to find the file in the project\src\main\resources\ folder, but you can put db.properties in the project\db.properties and specify how in your example
FetchData.class.getClassLoader().getResourceAsStream("db.properties")) - Chubatiysrcand again just call without/. Do you havejava.lang.NullPointerException? - Chubatiy