All Forums Connectivity
oopexpert 2 posts Joined 02/16
06 Apr 2016
Retreiving database name from JDBC connection

The connection URL for JDBC I use:
I know that you can get the current database by querying it with "select database".
My question is:
Is there any "lightweight" way to retreive the database name specified in the JDBC connection string from the java.sql.Connection-Object WITHOUT building a statement, executing it and parsing the resultset?

tomnolan 594 posts Joined 01/08
07 Apr 2016

The short answer is No.
The longer answer is...
I covered this topic in my blog
The Teradata JDBC Driver does not attempt to keep track of the session's current database setting. For example, a stored procedure could change the session's current database setting, and the Teradata JDBC Driver would not be informed.
It's difficult to offer advice since you didn't explain what you're trying to accomplish. Please give us the bigger picture of what your application needs to do, and we may be able to suggest a way to do it.

oopexpert 2 posts Joined 02/16
09 Apr 2016

The answer was helpful in the sense that there is no way to retreive the database name on the server side that was initially specified in the connection string and I am not wasting any more time on it :-). Using the following statements in a standard sql query with standard ResultSet will do the job for me as I am not switching databases:
"help session" (5. column)
"select database" (1. column)
Thank you

You must sign in to leave a comment.