Guest User

Untitled

a guest
Sep 10th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. package de.ktpvp.de.FFA.mysql;
  2.  
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6.  
  7.  
  8.  
  9. public class Connector {
  10.  
  11. public static String host = "localhost";
  12. public static String port = "3306";
  13. public static String database = "FFA";
  14. public static String username = "localhost";
  15. public static String password = "ZockerBoysHD1";
  16.  
  17. public static java.sql.Connection con;
  18.  
  19.  
  20. public static void connect(){
  21. if(!isConnected()){
  22. try {
  23. con = DriverManager.getConnection("jdbc:mysql//"+host+":"+port+"/"+database,username,password);
  24. System.out.println("[MySQL] Verbindung aufgebaut!");
  25. } catch (SQLException e) {
  26. e.printStackTrace();
  27. }
  28. }
  29.  
  30.  
  31.  
  32. }
  33. public static void disconnect(){
  34. if(isConnected()){
  35. try {
  36. con.close();
  37. System.out.println("[MySQL] Verbindung Geschlossen!");
  38. } catch (SQLException e) {
  39. e.printStackTrace();
  40. }
  41. }
  42.  
  43. }
  44. public static boolean isConnected(){
  45.  
  46. return(con == null ? false : true);
  47.  
  48.  
  49. }
  50. public static void Update(String qry){
  51. java.sql.PreparedStatement ps;
  52. try {
  53. ps = con.prepareStatement(qry);
  54. ps.executeUpdate();
  55. } catch (SQLException e1) {
  56. e1.printStackTrace();
  57. }
  58.  
  59.  
  60. }
  61. public static ResultSet getResult(String qry){
  62. try {
  63. java.sql.PreparedStatement ps = con.prepareStatement(qry);
  64. return ps.executeQuery();
  65. } catch (SQLException e) {
  66. e.printStackTrace();
  67. }
  68. return null;
  69.  
  70. }
  71. }
Add Comment
Please, Sign In to add comment