Skip to content

Instantly share code, notes, and snippets.

@kamaubrian
Created November 14, 2017 17:43
Show Gist options
  • Save kamaubrian/eb114ffc184a08a53db9b9dde17c337b to your computer and use it in GitHub Desktop.
Save kamaubrian/eb114ffc184a08a53db9b9dde17c337b to your computer and use it in GitHub Desktop.
*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Model;
import Model.utils.*;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
This is a Database Class for MySQL database, for netbeans,paste this on a class called Base,
Also add jar Library called Mysql JDBC connector.
* @author Brian-Kamau
*/
public abstract class Base {
public static String dbUsername ="root"; //Put your database Username
public static String dbPassword=""; ///Put your database password
public static String dbUrl="jdbc:mysql://localhost:3306/NameofYourDatabase?useSSL=false";
protected Statement stat = null;
protected Connection conn = null;
protected PreparedStatement pst = null;
protected ResultSet rst = null;
/*
Include dbDriver if using java 1.5 -> com.mysql.cj.Driver
include class.forName(dbDriver) for it to work
*/
public boolean getConnection() throws SQLException{
/*
include class.forName(com.mysql.cj.Driver);
*/
conn=DriverManager.getConnection(dbUrl, dbUsername, dbPassword);
return true;
}
public boolean closeConnection() throws SQLException{
if(!conn.isClosed()){
conn.close();
}
return true;
}
}
}
@kamaubrian
Copy link
Author

MYSQL java class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment