-: mysqldatabase singel connectie

Author
Lieven Roegiers
Description
mysql 0.5 user->root , password->root

rest succesfull thinking
Visits
260
Share
Digg Del.icio.us Reddit Simpy StumbleUpon Furl Yahoo Spurl Google Blinklist Blinkbits Ma.Gnolia Technorati Newsvine Netvouz Slashdot Netscape
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;
    }