• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

How to get the "connection" information?  RSS feed

 
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!
 
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/
 
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
 
Hot dog! An advertiser loves us THIS much:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!