Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package model;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- //import com.mysql.*;
- public class DataBase {
- protected Connection connection;
- protected Statement statment;
- protected ResultSet rs;
- public static DataBase d = DataBase.GetInsatance();
- private DataBase() {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- try {
- connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/lab", "root", "mysql_password");
- statment = connection.createStatement();
- } catch (SQLException e) {
- System.out.println("Not connected!");
- e.printStackTrace();
- }
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- System.out.println("Class not Found! shitt!!");
- e.printStackTrace();
- } catch (InstantiationException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IllegalAccessException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- public static DataBase GetInsatance() {
- if (d == null)
- return d = new DataBase();
- try {
- if (d.connection.isClosed())
- d = new DataBase();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- d = new DataBase();
- }
- return d;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement