Skip to content

Instantly share code, notes, and snippets.

@vmwarecode
Created January 24, 2016 02:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmwarecode/4cd32dee62962c2e561a to your computer and use it in GitHub Desktop.
Save vmwarecode/4cd32dee62962c2e561a to your computer and use it in GitHub Desktop.
Get Database Names from a SQL Server
//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