Results 1 to 5 of 5
Thread: Database name
- 02-06-2012, 08:09 PM #1
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
Database name
I have connection to mySQL database through JDBC, and need database name.
Say databaseURL is:
Only way I have found till now is to extract database name from databaseURL, like this:Java Code:jdbc:mysql://localhost:3306/test
Is there a way to get database name on some other way, using DatabaseMetaData, because I just can not find such method?Java Code:String databaseName = connection.getMetaData().getURL().substring (connection.getMetaData().getURL().lastIndexOf('/') + 1);
- 02-06-2012, 09:03 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: Database name
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, butIs there a way to get database name on some other way
I think that getURL is the only possibilityusing DatabaseMetaData, because I just can not find such method?
- 02-06-2012, 09:50 PM #3
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
- 02-08-2012, 11:07 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,466
- Rep Power
- 16
Re: Database name
As eRaaa asks, why do you need it?
I'd have thought you'd know what db you were looking at...
- 02-09-2012, 02:28 AM #5
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
Re: Database name
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
-
Client-Database vs Client-Server-Database Setup
By xxSLRxx in forum New To JavaReplies: 5Last Post: 01-06-2012, 09:53 AM -
Relational Database or Object Database?
By mattlindsay in forum New To JavaReplies: 8Last Post: 09-24-2011, 06:44 PM -
Database Changes
By MarkusHendersonicus in forum JDBCReplies: 17Last Post: 12-27-2010, 05:21 AM -
How to convert access database to mysql database?
By vrk in forum Advanced JavaReplies: 2Last Post: 02-11-2009, 04:43 AM -
Database in a PDA
By percivalwcy in forum JDBCReplies: 2Last Post: 08-08-2007, 03:10 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks