First time working with Databases, I'm trying to make an application with an embedded JavaDB. I'm looking in my book Big Java, and I came across this class which the book uses,
I created a properties file to give url, name, and password.import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; /** A simple data source for getting database connections. */ public class SimpleDataSource { /** Initializes the data source. @param fileName the name of the property file that contains the database driver, URL, username, and password */ public static void init(String fileName) throws IOException, ClassNotFoundException { Properties props = new Properties(); FileInputStream in = new FileInputStream(fileName); props.load(in); String driver = props.getProperty("jdbc.driver"); url = props.getProperty("jdbc.url"); username = props.getProperty("jdbc.username"); password = props.getProperty("jdbc.password"); Class.forName(driver); } /** Gets a connection to the database. @return the database connection */ public static Connection getConnection() throws SQLException { return DriverManager.getConnection(url, username, password); } private static String url; private static String username; private static String password; }
In another class, the code contains a line that says :
SimpledataSource.init(args[0])
I'm confused what this means. Does args[0] somehow point to the properties file?
And since this is the first time I'm using databases, am I heading in the right approach with this project? I plan on creating connections throughout another class to communicate with the database.