• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to get the "connection" information?

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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/
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
problem resolved.

Thank You
 
Forget Steve. Look at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic