I wrote following the java program
import java.io.*;
import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet
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.