I am trying to find out a SQL query through which i can get to know if i am connected to database or not. I will be using JAVA program for executing this query. I am in search of a generic query that when executed from my java program can give me a result if i am connected to database. I am not aware of the database structure(tables in database), i just know database name, to which i am trying to connect.
I am in search of a generic SQL query which can work on any database irrespective of the underlying database such as SQL Server, MySql, Oracle
or any other.
Till now i have got some queries but they are database specific they cannot be used with every database.
select count(*) as TablesCount from sys.tables
:- this query isSQL server
specific.select 1
:- works for every database but according to me this is not a good aproach.show tables
:- i cannot use show tables as thiquery displays the name of tables in the database
but i am just concerned whether i can access database or not.
- question 1:- Please suggest if i can make a query that can execute irrespective of underlying database(I am not aware of database structure).
- question 2:- can i store result of query (query - show tables) in resultset.