Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Is there any way to change postgreSQL current database from java application? or is there any equivalent for \connect report ? I know i can do this by changing JDBC connection string, but is there any better alternative?

share|improve this question
    
It is always better to have different datasources configured for different databases running in the same server. A connection at any point will point to only one database and you cannot change it. You can only open a new connection –  Abhijith Nagarajan Oct 28 '13 at 14:23
    
maybe i should have described my solution, i need to list all databases to user and connect to one of them on his/her demand. –  MoienGK Oct 28 '13 at 14:27
2  
You can't CHANGE a connection. You can either OPEN or CLOSE it. If you want to work with a different databases, simple create a new connection to it. If you want don't want the previous connection, simply close it. Changing a data-source simply doesn't make sense. –  user2339071 Oct 28 '13 at 14:27
1  
@dave, So let the user make the selection, and append it to the JDBC connection string. If the user wants to change the connection, they will select which new database to connect to, right. So, close the previous connection, and create a new connection to the newer database. –  user2339071 Oct 28 '13 at 14:30
    
@user2339071 thats what i am doing now, question raised when i tried to find simpler or maybe more elegant way. from what i learned from comments current way is the elegant one . –  MoienGK Oct 28 '13 at 14:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.