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?
The short answer is No.
The longer answer is...
I covered this topic in my blog https://developer.teradata.com/blog/tomnolan/2012/03/how-to-determine-or-switch-the-current-database...
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.
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)