Guest User

Untitled

a guest
Mar 15th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. /*
  2. Title: SimpleDataSource
  3. Author: Ebowoicho E. Onah
  4. Last Edit: 29/10/2011
  5.  
  6. This is a proxy for accessing the Database
  7. */
  8. package laboratory2;
  9.  
  10. import java.util.*;
  11. import java.io.*;
  12. import java.sql.*;
  13.  
  14. public class SimpleDataSource
  15. {
  16. private static String url;
  17. private static String username;
  18. private static String password;
  19.  
  20. public static void init(String database) throws IOException, ClassNotFoundException, SQLException
  21. {
  22. Properties props = new Properties();
  23. FileInputStream in = new FileInputStream(database);
  24. props.load(in);
  25.  
  26. String driver = props.getProperty("jdbc.driver");
  27. url = props.getProperty("jdbc.url");
  28. username = props.getProperty("jdbc.username");
  29. if (username == null) username = "root";
  30. password = props.getProperty("jdbc.password");
  31. if (password == null) password = "puss";
  32. if (driver !=null)
  33. Class.forName(driver);
  34. }
  35.  
  36. public static Connection getConnection() throws SQLException
  37. {
  38. return DriverManager.getConnection(url, username, password);
  39. }
  40. }
Add Comment
Please, Sign In to add comment