Created
September 1, 2022 08:52
-
-
Save optyler/11d31fcc0408252658ff2b508b787012 to your computer and use it in GitHub Desktop.
get tables names through jdbc connectors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.Connection | |
import java.sql.DatabaseMetaData | |
import java.sql.DriverManager | |
def mysql_connection_string = 'jdbc:mysql://toto.com/tata_db' | |
// If you are on dev you can disable ssl certificate verification | |
def sqlserver_connection_string = 'jdbc:sqlserver://42.42.42.42:1433;databaseName=tata_db;useSSL=false;integratedSecurity=false;encrypt=true;trustServerCertificate=true' | |
Connection con = DriverManager.getConnection(sqlserver_connection_string, 'John', 'Doe') | |
DatabaseMetaData dbMetaData = con.getMetaData() | |
new String[] types = {"TABLE"} | |
rs = dbMetaData.getTables(null, null, "%", types) | |
while (rs.next()) { | |
println rs.getString("TABLE_NAME") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment