if the user you are using is a superuser or a db owner... then try to use the following...
Main Topics
Browse All TopicsI want to drop a postgres using jdbc. I believe this code
Statement statement = m_conn.createStatement();
statement.execute("DROP Database "+m_project);
is logically correct. but if m_conn is the connection to the same db, then the db is still open, and the drop fails.
how do I get a connection which does not keep the db open, so I can drop it?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
'drop database ' will not work if you or anyone has connected to the database... so use 'dropdb' command.
for more info...
http://www.postgres
h
check the sample code from below link...
http://oracle.anilp
Statement statement = m_conn.createStatement();
statement.execute("dropdb "+m_project);
I get
org.postgresql.util.PSQLEx
is there some misunderstanding. as I see it, dropdb is a postgres command you enter at the postgres prompt. the code example you provided are jdbc calls inside Java Statements. to me they are not the same. as the test result shows, it does not work that way.
would you like to explain my original question, how would you call a postgres command from inside java?
That depends on your needs and possibilities. Generally speaking I would not suggest to drop databases from software. But if there's the need, you have the two options as mentioned above.
You might call dropdb as an external application depending on your access rights to the executables (if installed). In this case you should pass the complete path to the dropdb executable and pass also hostname, username and password with appropriate user rights via command line or environment.
You can also use the drop databa command as mentioned in my last comment. There you need to have the right to connect to another database to drop the database. The attached (pseudo) code is used by us sometimes (usually we do not drop databases from the software)
Business Accounts
Answer for Membership
by: JagdishDevakuPosted on 2009-07-31 at 23:21:27ID: 24994321
please check
whethere the user from which you are connecting to Postgresql has the permissions to drop or not..?