import java.sql.*;


public class Konec{
  public  Connection conn;
  public  Statement st;
  public  ResultSet rs;

         // menciptakan fungsi konec()
 public void koneksi()
 {
        // mamangil fungsi konek() untuk melakukan koneksi
  konek("localhost","databases","root","password");
 }

        // block dibawah ini intinya fungsi/method buat koneksi

      // fungi konek

public  void konek(String server,String db, String user,String passwd){
    System.out.println("Keterangan");

         try {
        Class.forName("com.mysql.jdbc.Driver");

      } catch (ClassNotFoundException e) {
        System.out.println(
           "Ada kesalahan Driver ODBC tidak barhasil Load");
        e.printStackTrace();
        return;
      }
       System.out.println("Mysql JDBC Driver berhasil di Load");
      conn = null;
           try {
          conn = DriverManager.getConnection("jdbc:mysql://"+
             server+":3306/"+db,user,passwd);
                  } catch (SQLException e) {
        System.out.println("Tidak bisa koneksi ke database");
        e.printStackTrace();
        return;
      }

      if (conn != null)
          System.out.println("Berhasil Koneksi!");
      else
              System.out.println("Koneksi Gagal........ !");
   }
}
Categories:

0 comments:

Post a Comment

Subscribe to RSS Feed Follow me on Twitter!