classkoneksi
/*
* 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 Class;
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author RPL
*/
public class classkoneksi {
public static Connection setKoneksi(){
String konString = "jdbc:mysql://localhost:3306/db_penjualanbuku";
Connection koneksi = null;
try{
Class.forName("com.mysql.jdbc.Driver");
koneksi = (Connection) DriverManager.getConnection(konString,"root","");
System.out.println("koneksi berhasil");
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(classkoneksi.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("koneksi gagal");
}
return koneksi;
}
public static int execute(String SQL){
int status = 0;
Connection koneksi = setKoneksi();
try {
Statement st = koneksi.createStatement();
status = st.executeUpdate(SQL);
} catch (Exception e) {
Logger.getLogger(classkoneksi.class.getName()).log(Level.SEVERE, null, e);
}
return status;
}
public static ResultSet executeQuery(String SQL){
ResultSet rs = null;
Connection koneksi = setKoneksi();
try {
Statement st = koneksi.createStatement();
rs = st.executeQuery(SQL);
} catch (Exception e) {
Logger.getLogger(classkoneksi.class.getName()).log(Level.SEVERE, null, e);
}
return rs;
}
}
* 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 Class;
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author RPL
*/
public class classkoneksi {
public static Connection setKoneksi(){
String konString = "jdbc:mysql://localhost:3306/db_penjualanbuku";
Connection koneksi = null;
try{
Class.forName("com.mysql.jdbc.Driver");
koneksi = (Connection) DriverManager.getConnection(konString,"root","");
System.out.println("koneksi berhasil");
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(classkoneksi.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("koneksi gagal");
}
return koneksi;
}
public static int execute(String SQL){
int status = 0;
Connection koneksi = setKoneksi();
try {
Statement st = koneksi.createStatement();
status = st.executeUpdate(SQL);
} catch (Exception e) {
Logger.getLogger(classkoneksi.class.getName()).log(Level.SEVERE, null, e);
}
return status;
}
public static ResultSet executeQuery(String SQL){
ResultSet rs = null;
Connection koneksi = setKoneksi();
try {
Statement st = koneksi.createStatement();
rs = st.executeQuery(SQL);
} catch (Exception e) {
Logger.getLogger(classkoneksi.class.getName()).log(Level.SEVERE, null, e);
}
return rs;
}
}
Comments
Post a Comment