Advertisement
Guest User

Koneksi.java

a guest
May 26th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package dnacoffee;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.sql.Statement;
  13. import javax.swing.JOptionPane;
  14.  
  15. /*
  16.  *
  17.  * @author Bagos
  18.  */
  19. public class Koneksi {
  20.     private static Connection conn;
  21.         public static Connection getConnection(){
  22.         String url = "oracle.jdbc.driver.OracleDriver";
  23.         String database = "jdbc:oracle:thin:@localhost:1521:XE";
  24.         String username = "bagus_6628";
  25.         String password = "admin";
  26.         try{
  27.             conn = (Connection) DriverManager.getConnection(database,username,password);
  28.         }catch (SQLException err){
  29.             JOptionPane.showMessageDialog(null, "GAGAL KONEKSI!!!");
  30.         }
  31.         return conn;
  32.         }
  33.         void putData(String sql){
  34.         try{
  35.                     Connection con = getConnection();
  36.                     Statement state = con.createStatement();
  37.                     state.executeUpdate(sql);
  38.                     state.close();
  39.         } catch(Exception ex){
  40.  
  41.         }
  42.     }
  43.     public Statement state;
  44.     public ResultSet getData(String sql) throws Exception {
  45.         Connection con = getConnection();
  46.         state = con.createStatement();
  47.         ResultSet rset = state.executeQuery(sql);
  48.         return rset;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement