Advertisement
Guest User

Untitled

a guest
Oct 7th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. package me.eliteSchwein.PRcore_addon;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9.  
  10. public class MySQL{
  11. public static String host = "localhost";
  12. public static String port = "3306";
  13. public static String database = "PRban";
  14. public static String username = "5spce59n6WKVGarv";
  15. public static String password = "5spce59n6WKVGarv";
  16. public static Connection con;
  17.  
  18. public static void connect(){
  19. if(!isConnected()){
  20. try {
  21. con = DriverManager.getConnection("jdbc:mysql://PureResolution.net/PRban", username, password);// + host + "/" + database, username, password);
  22. System.out.println("[PRban-Mysql]verbunden");
  23. } catch (SQLException e) {
  24. // TODO Auto-generated catch block
  25. e.printStackTrace();
  26. }
  27.  
  28. }
  29.  
  30. }
  31. public static void disconnect(){
  32. if(isConnected()){
  33. try {
  34. con.close();
  35. System.out.println("[PRban-Mysql]getrennt");
  36. } catch (SQLException e) {
  37. // TODO Auto-generated catch block
  38. e.printStackTrace();
  39. }
  40. }
  41. }
  42. public static boolean isConnected(){
  43.  
  44. return (con == null ? false : true);
  45. }
  46. public static void update(String qry){
  47. try {
  48. con.createStatement().executeUpdate(qry);
  49. } catch (SQLException e) {
  50. // TODO Auto-generated catch block
  51. e.printStackTrace();
  52. }
  53. }
  54. public static ResultSet getResult(String qry){
  55.  
  56. try {
  57. con.createStatement().executeQuery(qry);
  58. } catch (SQLException e) {
  59. // TODO Auto-generated catch block
  60. e.printStackTrace();
  61. }
  62. return null;
  63. }
  64. public static void ExecuteCommand(String command)
  65. {
  66. try
  67. {
  68. if (con.isClosed()) {
  69. connect();
  70. }
  71. Statement st = con.createStatement();
  72. st.executeUpdate(command);
  73. }
  74. catch (SQLException e5)
  75. {
  76. System.out.println("[MySQLAPI] Fehler 04");
  77. System.out.println("[MySQLAPI] Es ist ein Fehler beim Ausfuehren des Befehls aufgetreten!");
  78. e5.printStackTrace();
  79. }
  80. }
  81. public static Connection getConnection(){
  82. return con;
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement