I’m writing a program that uses JDBC and connects to a database and does some edits / deletes. I need to put the URL, username, and password fields into a build.properties file, but I’m not sure how this would look or how to really get this to work.
(I’m completely new to this and haven’t found any resources related to this specifically)
For example, in my code I have something like this :
String username = "something"
String password = "something"
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@(DESCRIPTION=(ENABLE=BROKEN)" + "(FAILOVER=ON)(LOAD_BALANCE=ON)(ADDRESS=(PROTOCOL=TCP) ... etc", username, password);
and I want to put this in build.properties and for my code to create the connection using these properties instead of how I’m doing it now.
Any help would be appreciated!
Something like this:
First, create database.properties:
Second, put the database.properties in your CLASSPATH.
Code looks something like this:
I didn’t compile it, and I’m not sure if the syntax is 100% correct, but this illustrates the main idea.