Guest User

Untitled

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