package be.sample
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
*
* @author Lieven Roegiers
*/
public class DataConnect {
//Deze gebruiker is de standaard administrator met alle rechten
private String user = "root" ;
private String pwx = "root";
//Definieer de URL van de mysql server op de localhost
private String url = "jdbc:mysql://localhost:3306";
private Connection con ;
private static final DataConnect instance = new DataConnect();
public static DataConnect getInstance(){
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return instance;
}
public void startcon() throws SQLException{
//todo thread voor het openhouden van de connectie
con = DriverManager.getConnection(url ,user , pwx );
}
public void stopcon() throws SQLException{
//todo thread voor het sluiten van de connectie na 10 min niet gebruikt te zijn
con.close();
}
public Statement getStmt() throws SQLException {
return con.createStatement();
}
public void finalize() throws SQLException{
this.stopcon();
this.con = null;
}