Created
January 24, 2016 02:00
-
-
Save vmwarecode/4cd32dee62962c2e561a to your computer and use it in GitHub Desktop.
Get Database Names from a SQL Server
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
//Action Inputs: | |
// hostname : string | |
// instance : string | |
// domain : string | |
// user : string | |
// password : SecureString | |
//Action Result: Array/string | |
var jdbc = new JDBCConnection; | |
var url = "jdbc:jtds:sqlserver://"+hostname | |
if (instance != null && instance.length > 0){ | |
url = url+";instance="+instance; | |
} | |
if (domain != null && domain.length > 0) { | |
url = url+";domain="+domain; | |
} | |
var connection = jdbc.getConnection(url,user,password); | |
var statement = connection.prepareStatement("SELECT name FROM sys.databases"); | |
var result = statement.executeQuery(); | |
var dbNames = []; | |
while (result.next()){ | |
dbNames.push(result.getString("name")); | |
} | |
return dbNames; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment