Hi, StackOverflow community :)
I come to you to share one of my problems ...
I need to extract a list of each table in each database instance of SQL Server , I found this query:
EXEC sp_msforeachdb 'Use ?; SELECT DB_NAME() AS DB, * FROM sys.tables'
It works fine on Microsoft SQL Server Management Studio, but when I try to execute it in my Java program (including JDBC drivers for SQL Server), it says that it does not return any result .
My Java code is as follows:
this.statement = this.connect.createStatement(); // Create the statement this.resultats = this.statement.executeQuery("EXEC sp_msforeachdb 'Use ?; SELECT DB_NAME() AS DB, * FROM sys.tables'"); // Execute the query and store results in a ResultSet this.sortie.ecrireResultats(this.statement.getResultSet()); // Write the ResultSet to a file
Thanks to everyone who tries to help me. Have a nice day :)
EDIT 1:
I'm not sure if the SQL Server JDBC driver supports my query, so I will try to achieve my goal differently.
What I'm trying to get is a list of all the tables for each database instance of SQL Server , the output format will be as follows:
+-----------+--------+ | Databases | Tables | +-----------+--------+
So now I am asking if anyone can help me get to this solution using SQL queries via Java JDBC for the SQL Server driver .
I also want to thank the quickest answers I received from Tim Lenner and Mark Rottwevel .