Wave Wave - 1 year ago 89
Java Question

Using java to find version and start PostgreSQL

Is it possible to find version of PostgreSQL using java and also to start the PostgreSQL server using java code ?

To find version we have PG_VERSION file which has version under PostgreSQL data directory but we cannot rely on it since this file can be edited. Please help me out. Any suggestions are really appreciated.

Answer Source

Quick googling reveals the query:

select version();

Run it through JDBC, you have java anyway. As for running the the postgres server itself, I think the old way Runtime.exec/ProcessBuilder will do the job. You may want to create some kind of script above it but that the way it should work, I guess, there is no other way.

If you're running on linux machine, maybe you should install the server as a service and run it respectively, but from the point view of Java (if you really want to run it from java) its still an invocation of external process.

Hope this helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download