Showing posts with label Database postgresql. Show all posts
Showing posts with label Database postgresql. Show all posts

Tuesday, July 17, 2018

Konfig hibernate.cfg

Konfig hibernate.cfg  - Sedikit catatan untuk koneksi database via hibernate. Jika kita mempunyai aplikasi server yang terpisah dengan database server, lalu aplikasi servernya menggunakan framework hibernate untuk mengurus databasenya maka konfigurasinya seperti ini.


<session-factory>
   <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
   <property name="hibernate.connection.url">jdbc:postgresql://22.12.123.xx:5432/thetable</property>
  
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
  
<property name="hibernate.connection.username">postgres</property>
  
<property name="hibernate.connection.password">postgres123</property>
  
<property name="hibernate.show_sql">true</property>
  
<property name="hibernate.format_sql">true</property>
</session-factory>
Kalau database dan aplikasinya disatuin dalam satu server, mungkin pada bagian hibernate.connection.url hanya seperti ini:
 <property name="hibernate.connection.url">jdbc:postgresql:thetable</property>
Kita langsung menuliskan databasenya saja. Oke begitu saja. Kalau tidak paham bisa cari di google. Karena ini untuk nambah catatan saya aja :hammer
Sekian dan wassalam :senyum

Remote Akses Database Postgresql

Remote Akses Database Postgresql - Hari ini mau tulis tentang remote akses postgresql, misalnya kita ingin konek ke server database dari pc rumah ke server database kantor. Untuk postgresql memang ada sedikit konfig pada file pg_hba.conf dan postgresql.conf, karena postgresql sedikit lebih secure untuk masalah koneksi ke database. Langsung aja;


Buka file pg_hba.conf :
         sudo vim /etc/postgresql/9.1/main/pg_hba.conf
Tambah line berikut
         host    all     all       202.129.xxx.0/24       trust
Buka file postgresql.conf :
         sudo vim /etc/postgresql/9.1/main/postgresql.conf
Uncoment line berikut :
        # listen_addresses = '*'
                 jadi
        listen_addresses = '*'
                 atau
        listen_addresses = '192.168.8.1 192.168.8.4'
Setelah itu disimpan, lalu restart server postgresqlnya
        sudo /etc/init.d/postgresql restart

Jalankan perintah
        psql -h 202.129.xxx.xx0 -d dbname -U ardi

Kalau tidak ada masalah, pasti langsung masuk ke databasenya. Mudah bukan. Sekian dari saya, kalau ada yang kurang paham bisa lihat di sini.
Sekian. Wassalam :senyum