I wrote following the java program
import java.io.*;
import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet
Just use the jar command to extract the files your application needs to make the connection with the database server. e.g. jar -xf jdbc_file. Compile it with the javac -cp . and run it with the java -cp .
And that's it. It will work.
You are using a JDBC 3 driver. JDBC 4 drivers are loaded automatically loaded by the DriverManager
whereas JDBC 3 drivers are not. Therefore you need to invoke
Class.forName("org.postgresql.Driver");
once in your application, (prior to invoking DriverManager#getConnection
).
Alternatively, you can use the JDBC 4 PostgreSQL driver from here which will not require the above method call.
Use
DriverManager.registerDriver(new org.postgresql.Driver());