Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. package Data;
  2.  
  3.  
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.SQLException;
  7.  
  8.  
  9. public class DBConnector {
  10. private Connection connection = null;
  11.  
  12. //Constants
  13. private static final String IP = "localhost";
  14. private static final int PORT = 3306;
  15. public static final String DATABASE = "skole_mysql_web";
  16. private static final String USERNAME = "root";
  17. private static final String PASSWORD = "root";
  18.  
  19. public DBConnector() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
  20. Class.forName("com.mysql.jdbc.Driver").newInstance();
  21. String url = "jdbc:mysql://" + IP + ":" + PORT + "/" + DATABASE;
  22. this.connection = (Connection) DriverManager.getConnection(url, USERNAME, PASSWORD);
  23. }
  24.  
  25. public Connection getConnection() {
  26. return this.connection;
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement