Advertisement
kazuhiroken

koneksi.java

Mar 1st, 2017
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. /**
  4.  *
  5.  * @author RPL
  6.  */
  7. public class koneksi {
  8.    
  9.    
  10.     public static Connection setKoneksi(){
  11.         Connection cn =null;
  12.         try{
  13.             Class.forName("com.mysql.jdbc.Driver");
  14.             cn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/db_buku","root","");
  15.         }catch(Exception e){
  16.             System.out.println(e);
  17.         }
  18.         return cn;
  19.     }
  20.    
  21.     public static int execute(String SQL){
  22.         int status = 0;
  23.         try{
  24.             Connection cn = setKoneksi();
  25.             Statement st = cn.createStatement();
  26.             status = st.executeUpdate(SQL);
  27.         }catch(Exception e){
  28.             System.out.println(e);
  29.         }
  30.         return status;
  31.     }
  32.    
  33.     public static ResultSet executeQuery(String SQL){
  34.         ResultSet rs = null ;
  35.         Connection cn = setKoneksi();
  36.         try{
  37.             Statement st = cn.createStatement();
  38.             rs = st.executeQuery(SQL);
  39.         }catch(Exception e){
  40.             System.out.println(e);
  41.         }
  42.         return rs;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement