I have a requirement where using java code I need to create/delete/alter postgres tables.
I have written a program as below:
public static void main(String[] args) throws IOException {
System.out.println("Hello World!");
Process p = Runtime.getRuntime().exec("psql -U postgres -d testdb -h localhost -p 5433 -f D:\test.sql");
}
test.sql file looks like below,
Create TABLE MyTable1
(
VersionNumber VARCHAR(32) NOT NUll
);
Create TABLE MyTable2
(
VersionNumber VARCHAR(32) NOT NUll
);
Create TABLE MyTable3
(
VersionNumber VARCHAR(32) NOT NUll
);
problem:
If I run the same psql command:
psql -U postgres -d testdb -h localhost -p 5433 -f D:\test.sql
in command line, it asks for password and the tables get created.
But in java program, there is not provision to provide password. Please let me know on how to achieve it.