Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Funktion;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class MySql {
- private static String username = "Darioko";
- private static String password = "";
- private static String database = "tablist";
- private static String host = "localhost";
- private static String port = "3306";
- private static Connection con;
- public static void connect(){
- if(!isConnected()){
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + host+":"+port+"/"+database,username,password);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void close(){
- if(isConnected()){
- try {
- con.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnected(){
- return con !=null;
- }
- public static void createTable(){
- if(isConnected()){
- try {
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Tablist (FUNC VARCHAR(100), String VARCHAR(100))");
- con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Farbrang (PG VARCHAR(100), String VARCHAR(100))");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void update(String qry){
- if(isConnected()){
- try {
- con.createStatement().executeUpdate(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static ResultSet getResult(String qry){
- if(isConnected()){
- try {
- return con.createStatement().executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement