Thread: Embedding Postgres in Java Application
I am developing a desktop GUI application and am using postgres 8. I need to be able to embed/bundle postgres with my application. To start with I am releasing on windows with Linux and OSX later. Is there a way of creating a JDBC connection to the db not over a network socket? The other way is going to be to start/stop the database from Java by calling "pg_ctl start/stop". But that issues with this because of the windows restrictions that postgres can't be run as a user with admin privileges. Any Ideas? Many Thanks Jasper Potts
On Sun, 16 Jan 2005, Jasper Potts wrote: > Is there a way of creating a JDBC connection to the db not over a > network socket? No. Java does not have support for unix sockets. > The other way is going to be to start/stop the database from Java by > calling "pg_ctl start/stop". But that issues with this because of the > windows restrictions that postgres can't be run as a user with admin > privileges. Any Ideas? > Even if Java did support unix sockets you would still have to start the server running. PostgreSQL is not designed to be an embedded database (especially not by Java). This doesn't seem like a great idea, perhaps one of the Java databases would be more appropriate for this task? Kris Jurka
I have tested most of the other options Hypersonic, Firebird, Daffodil and Postgres is much faster with large data sets and a lot better on memory usage. I have not tried Cloudscape as that was only very recently released under a license that would allow me to embed it. The query times with Postgres are in the 1-5sec range comparing to 30sec plus on the others. Hypersonic can be quick but only with the entire table in memory, gets nasty with outer joins. Are there are any I haven't tried and should be looking at? I am using Hibernate as a middle layer so porting should not be an issue. Thanks Jasper Kris Jurka wrote: >On Sun, 16 Jan 2005, Jasper Potts wrote: > > > >>Is there a way of creating a JDBC connection to the db not over a >>network socket? >> >> > >No. Java does not have support for unix sockets. > > > >>The other way is going to be to start/stop the database from Java by >>calling "pg_ctl start/stop". But that issues with this because of the >>windows restrictions that postgres can't be run as a user with admin >>privileges. Any Ideas? >> >> >> > >Even if Java did support unix sockets you would still have to start the >server running. PostgreSQL is not designed to be an embedded database >(especially not by Java). This doesn't seem like a great idea, perhaps >one of the Java databases would be more appropriate for this task? > >Kris Jurka > >
Jasper Potts wrote: > I am developing a desktop GUI application and am using postgres 8. I > need to be able to embed/bundle postgres with my application. To start > with I am releasing on windows with Linux and OSX later. > > Is there a way of creating a JDBC connection to the db not over a > network socket? not only does JDBC not support unix sockets, neither does Windows. > The other way is going to be to start/stop the database from Java by > calling "pg_ctl start/stop". But that issues with this because of the > windows restrictions that postgres can't be run as a user with admin > privileges. Any Ideas? I'd suggest your windows installer install postgres as a system service by cloning the operation of the standard windows installer for pgsql, and you use localhost for your database connections. If you're using a java installer that doesn't understand windows services, maybe you could put it in a MSI (Microsoft Installer) wrapper that invokes both Postgres's MSI based installation and your java installer.
John R Pierce wrote: > > I'd suggest your windows installer install postgres as a system > service by cloning the operation of the standard windows installer for > pgsql, and you use localhost for your database connections. If > you're using a java installer that doesn't understand windows > services, maybe you could put it in a MSI (Microsoft Installer) > wrapper that invokes both Postgres's MSI based installation and your > java installer. > I think thats probably the way to go, at least for the Win 2000/XP users. Any idea if Postgres 8 will work with Win 98/Me? My guess is not from what I have seen, talk about NTFS dependencies on the general mailing list. So will probably go for Hypersonic for those guys, as its simple and copes well if you don't push the database too large. Is the src for the Postgres installer available? to use as a starting point. Thanks Jasper
You might also consider Derby (formerly Cloudscape), which IBM contributed via open source. I've found Hibernate an excellent tool for development. It has great support for postgresql and hypersonic; it is developing support for derby. Hibernate is an object - relational mapping tool. You write database calls in java using "object oriented" calls without worrying about the underlying database. Charlie Jasper Potts wrote: > John R Pierce wrote: > >> >> I'd suggest your windows installer install postgres as a system >> service by cloning the operation of the standard windows installer >> for pgsql, and you use localhost for your database connections. If >> you're using a java installer that doesn't understand windows >> services, maybe you could put it in a MSI (Microsoft Installer) >> wrapper that invokes both Postgres's MSI based installation and your >> java installer. >> > I think thats probably the way to go, at least for the Win 2000/XP > users. Any idea if Postgres 8 will work with Win 98/Me? My guess is > not from what I have seen, talk about NTFS dependencies on the general > mailing list. So will probably go for Hypersonic for those guys, as > its simple and copes well if you don't push the database too large. > > Is the src for the Postgres installer available? to use as a starting > point. > > Thanks > > Jasper > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster > >