Results 1 to 5 of 5

Thread: Database name

  1. #1
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Database name

    I have connection to mySQL database through JDBC, and need database name.

    Say databaseURL is:
    Java Code:
    jdbc:mysql://localhost:3306/test
    Only way I have found till now is to extract database name from databaseURL, like this:
    Java Code:
    String databaseName = connection.getMetaData().getURL().substring
                        (connection.getMetaData().getURL().lastIndexOf('/') + 1);
    Is there a way to get database name on some other way, using DatabaseMetaData, because I just can not find such method?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: Database name

    I am not sure why you need that?
    Is there a way to get database name on some other way
    Sure, e.g. with native select query, --> "SELECT DATABASE();" on mysql or SELECT DB_NAME() on sql server, but

    using DatabaseMetaData, because I just can not find such method?
    I think that getURL is the only possibility

  3. #3
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: Database name

    Quote Originally Posted by eRaaaa View Post
    I am not sure why you need that?

    Sure, e.g. with native select query, --> "SELECT DATABASE();" on mysql or SELECT DB_NAME() on sql server, but


    I think that getURL is the only possibility
    Does it mean DatabaseMetaData doesn't have database name value?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default Re: Database name

    As eRaaa asks, why do you need it?
    I'd have thought you'd know what db you were looking at...

  5. #5
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: Database name

    Quote Originally Posted by Tolls View Post
    As eRaaa asks, why do you need it?
    I'd have thought you'd know what db you were looking at...
    Well I was experimenting with some example that connects to database using fixed URL.
    Later in that application, I was using database name parameter for something, so I have choice to extract database name from fixed URL, or to obtain it from DatabaseMetaData.
    Or, as another poster says, to query database.

Similar Threads

  1. Client-Database vs Client-Server-Database Setup
    By xxSLRxx in forum New To Java
    Replies: 5
    Last Post: 01-06-2012, 09:53 AM
  2. Relational Database or Object Database?
    By mattlindsay in forum New To Java
    Replies: 8
    Last Post: 09-24-2011, 06:44 PM
  3. Database Changes
    By MarkusHendersonicus in forum JDBC
    Replies: 17
    Last Post: 12-27-2010, 05:21 AM
  4. Replies: 2
    Last Post: 02-11-2009, 04:43 AM
  5. Database in a PDA
    By percivalwcy in forum JDBC
    Replies: 2
    Last Post: 08-08-2007, 03:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •