Advertisement
Guest User

Untitled

a guest
Apr 6th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. package me.ase.CommandCheckerBlocker.DBConnect;
  2.  
  3. import java.sql.*;
  4.  
  5. public class databaseConnection {
  6. static private Connection connection;
  7.  
  8. public static Connection getConnection() throws ClassNotFoundException, SQLException {
  9. String host = HOST";
  10. String user = "USERNAME";
  11. String db = "DATABASE";
  12. String pass = "PASSWORD";
  13. if (connection == null) {
  14. try {
  15. Class.forName("com.mysql.jdbc.Driver");
  16. connection = DriverManager.getConnection("jdbc:mysql://" + host + "/" + db, user, pass);
  17. } catch (Exception e) {
  18. e.printStackTrace();
  19. }
  20. }
  21. return connection;
  22.  
  23. }
  24.  
  25. public static void setData(String string) throws Exception {
  26. databaseConnection.getConnection().createStatement().executeUpdate(string);
  27. }
  28.  
  29. public static ResultSet getData(String string) throws Exception {
  30. return databaseConnection.getConnection().createStatement().executeQuery(string);
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement