/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package Sambungan1; /** * Mencoba terkoneksi ke database PostgreSQL * @author Steven Nathaniel */ import java.sql.*; import java.sql.DriverManager; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; public class TestSambungan1 { private static final String DB_DRIVER = "org.postgresql.Driver"; private static final String DB_CONNECTION = "jdbc:postgresql://localhost:5432/belajar"; private static final String DB_USER = "steven"; private static final String DB_PASSWORD = "balikpapan"; public static void main (String[]argv){ System.out.println("----------PostgreSQL Setting " + "Koneksi JDBC---------"); //Connection connection = null; try{ Class.forName(DB_DRIVER); }catch (ClassNotFoundException e){ System.out.println("Di manakah letak PostgreSQL JDBC milik anda " + "Masukan ke Dalam Path Library Anda"); e.printStackTrace(); return; } System.out.println("Driver JDBC PostgreSQL Telah Terdaftar"); Connection connection = null; try{ connection=DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD); }catch(SQLException e){ System.out.println("Koneksi Telah Gagal! Periksa Tampilan console"); e.printStackTrace(); return; } if(connection != null){ System.out.println("Anda Berhasil Terhubung Ke Database, Silahkan Dimanfaatkan"); }else{ System.out.println("Anda Gagal Terhubung Ke Database"); } } }