• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the "connection" information?

 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I need to know the database name that is having linked with the "connection" object.

First, i make a connection to a particular host. like "jdbc:mysql://localhost:3306".

Then, according to the database name, the connection should be updated. like "jdbc:mysql://localhost:3306/databasename".


It can be done? if yes, let me know how to do?

Thank You!
 
Ed Ward
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if you're asking if you can actually change the database name or simply get a new connection to a named database.
If you just want to connect to a named database, then just do it when you create the connection via th DriverManager.
You may want to take a look at the vendor's JDBC driver docs though as sometimes they add on little extra features that are not in the spec (or remove ones that are open to interpretation).
I seem to recall working with one awhile back that initially used the database name if it was passd in the URL when getting the Connection and then stopped using it even if it was included. They had the change documented though.

http://download.oracle.com/javase/6/docs/api/
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you need a list of all the schemas in the database, you can doing by means of obtaining the DatabaseMetadata.

This code will print all the schemas in the database:



However, I am not sure if there is a way to know what is the current schema. I guess it may depend on the database. For instance, in Derby, the current schema is named as the user currently signed in. So, you could obtain the current user name from the MetaData and know that is your current schema



However, not all databases are the same, I guess you will have to explore how your driver works.
 
yuvaraj KumarAmudhan
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
problem resolved.

Thank You
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic