Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.Beam.Main;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Mysql {
- private static Connection con;
- private static String url = "jdbc:mysql://localhost:3306/Login";
- private static String host = "localhost";
- private static int port = 3306;
- private static String database = "Login";
- private static String user = "root";
- private static String password = "9329";
- /*
- public static Connection connect() throws Exception {
- try {
- con = DriverManager.getConnection(url,user,password);
- System.out.print("\nMYsql Verbindung wurde geOffent");
- return con;
- } catch (SQLException e) {System.out.println(e);}
- return null;
- }
- */
- public static boolean connectMySQL(){
- boolean connected = false;
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
- System.out.print("\nMYsql Verbindung wurde geOffent");
- connected = true;
- } catch (SQLException e) {
- System.out.print("\nMYsql Verbindung wurde geschlossen "+e);
- }
- return connected;
- }
- public static boolean isConnected() {
- boolean connected = false;
- if (con != null) {
- connected = true;
- }
- return connected;
- }
- public static void disconect() {
- if(isConnected()) {
- try {
- con.close();
- System.out.print("\nMYsql Verbindung wurde geschlossen");
- }catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static String hasPro(String user) {
- if(isConnected()) {
- try {
- Statement s = con.createStatement();
- ResultSet rs = s.executeQuery("SELECT user FROM Login WHERE user= '"+user+"'");
- while (rs.next()) {
- return rs.getString("user");
- }
- s.close();
- }catch (SQLException e) {
- System.out.print(e.getMessage());
- }
- }else {
- System.out.print("\nKeine Verbindung");
- }
- return null;
- }
- public static String getpass(String user) {
- if(isConnected()) {
- try {
- Statement s = con.createStatement();
- ResultSet rs = s.executeQuery("SELECT user FROM Login WHERE user= '"+user+"'");
- while (rs.next()) {
- return rs.getString("pass");
- }
- s.close();
- }catch (SQLException e) {
- System.out.print(e.getMessage());
- }
- }else {
- System.out.print("\nKeine Verbindung");
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement