Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. package de.Beam.Main;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9.  
  10. public class Mysql {
  11.  
  12. private static Connection con;
  13. private static String url = "jdbc:mysql://localhost:3306/Login";
  14. private static String host = "localhost";
  15. private static int port = 3306;
  16. private static String database = "Login";
  17. private static String user = "root";
  18. private static String password = "9329";
  19.  
  20. /*
  21. public static Connection connect() throws Exception {
  22. try {
  23. con = DriverManager.getConnection(url,user,password);
  24. System.out.print("\nMYsql Verbindung wurde geOffent");
  25. return con;
  26. } catch (SQLException e) {System.out.println(e);}
  27. return null;
  28. }
  29. */
  30.  
  31. public static boolean connectMySQL(){
  32. boolean connected = false;
  33. try {
  34. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
  35. System.out.print("\nMYsql Verbindung wurde geOffent");
  36. connected = true;
  37. } catch (SQLException e) {
  38. System.out.print("\nMYsql Verbindung wurde geschlossen "+e);
  39. }
  40. return connected;
  41. }
  42.  
  43. public static boolean isConnected() {
  44. boolean connected = false;
  45. if (con != null) {
  46. connected = true;
  47. }
  48. return connected;
  49. }
  50. public static void disconect() {
  51. if(isConnected()) {
  52. try {
  53. con.close();
  54. System.out.print("\nMYsql Verbindung wurde geschlossen");
  55. }catch (SQLException e) {
  56. e.printStackTrace();
  57. }
  58. }
  59. }
  60.  
  61.  
  62.  
  63.  
  64. public static String hasPro(String user) {
  65. if(isConnected()) {
  66. try {
  67. Statement s = con.createStatement();
  68. ResultSet rs = s.executeQuery("SELECT user FROM Login WHERE user= '"+user+"'");
  69.  
  70. while (rs.next()) {
  71. return rs.getString("user");
  72. }
  73. s.close();
  74. }catch (SQLException e) {
  75. System.out.print(e.getMessage());
  76. }
  77. }else {
  78. System.out.print("\nKeine Verbindung");
  79. }
  80. return null;
  81. }
  82.  
  83. public static String getpass(String user) {
  84. if(isConnected()) {
  85. try {
  86. Statement s = con.createStatement();
  87. ResultSet rs = s.executeQuery("SELECT user FROM Login WHERE user= '"+user+"'");
  88.  
  89. while (rs.next()) {
  90. return rs.getString("pass");
  91. }
  92. s.close();
  93. }catch (SQLException e) {
  94. System.out.print(e.getMessage());
  95. }
  96. }else {
  97. System.out.print("\nKeine Verbindung");
  98. }
  99. return null;
  100. }
  101.  
  102.  
  103.  
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement