We would like to know how to execute PostgresDB sql script through java code.
import java.io.BufferedReader; import java.io.InputStreamReader; /*from w w w . ja v a 2 s . c o m*/ public class Main { public static void main(String argv[]) throws Exception { String line; Process p = Runtime.getRuntime().exec( "psql -U username -d dbname -h serverhost -f scripfile.sql"); BufferedReader input = new BufferedReader(new InputStreamReader( p.getInputStream())); while ((line = input.readLine()) != null) { System.out.println(line); } input.close(); } }