Senin, 30 November 2009

Koneksi java ke postgresql

import java.sql.*;
public class koneksi {

public static void main(String [] args){
Connection conn=null;


try {
Class.forName("org.postgresql.Driver");
conn=DriverManager.getConnection("jdbc:postgresql://localhost:5432/UASPI?user=postgres&password=arik");
System.out.println("Koneksi ke Database Berhasil !!!");
if (conn==null)
System.err.println("Koneksi ke Database Gagal !!!");
else
// out.println("Koneksi ke Database Berhasil !!!");
System.err.println(" ");
}//end try
catch(ClassNotFoundException ex) {
System.err.println("Driver Error");
ex.printStackTrace();
System.exit(1);
}

catch(SQLException ex2) {
System.err.println("Tidak berhasil koneksi dg Postgresql server!!!");
System.exit(1);
}
}

}

untuk mengecek diperlukan driver postgresql dapat di donwload di sini

Tidak ada komentar:

Posting Komentar