Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 daos;
- import java.sql.*;
- /**
- *
- * @author ASUS
- */
- public class Connect {
- private static Connection Con;
- private static final String URL="jdbc:mysql://localhost:3306/for_Opp";
- private static final String Drivername="com.mysql.jdbc.driver";
- private static final String Username="root";
- private static final String Password="";
- public static Connection OpenCon(){
- if(Con==null){
- try{
- Class.forName(Drivername);
- try{
- Con=(com.mysql.jdbc.driver)
- DriverManager.getConnection(URL,Username,Password);
- }
- catch(SQLException sqle){
- System.out.println("Tidak terhubung ke database "+sqle);
- }
- }
- catch(ClassNotFoundException e){
- System.out.println("Driver not found "+e);
- }
- }
- return Con;
- }
- public static connection CloseCon(){
- if(kon != null){
- try{
- kon.close();
- }catch(SQLException e){
- System.out.println("Error "+e);
- }
- }
- return Con;
- }
- public static void main(String[]args){
- new Connect();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement