Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Title: SimpleDataSource
- Author: Ebowoicho E. Onah
- Last Edit: 29/10/2011
- This is a proxy for accessing the Database
- */
- package laboratory2;
- import java.util.*;
- import java.io.*;
- import java.sql.*;
- public class SimpleDataSource
- {
- private static String url;
- private static String username;
- private static String password;
- public static void init(String database) throws IOException, ClassNotFoundException, SQLException
- {
- Properties props = new Properties();
- FileInputStream in = new FileInputStream(database);
- props.load(in);
- String driver = props.getProperty("jdbc.driver");
- url = props.getProperty("jdbc.url");
- username = props.getProperty("jdbc.username");
- if (username == null) username = "root";
- password = props.getProperty("jdbc.password");
- if (password == null) password = "puss";
- if (driver !=null)
- Class.forName(driver);
- }
- public static Connection getConnection() throws SQLException
- {
- return DriverManager.getConnection(url, username, password);
- }
- }
Add Comment
Please, Sign In to add comment