When I use following java code to get namespace from AWD Databricks:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
public class DatabricksJDBCExample {
public static void main(String[] args) {
String jdbcUrl = "jdbc:spark://your-databricks-workspace-url:443/default;transportMode=http;ssl=true;httpPath=sql/protocolv1/o/your-org-id/your-workspace-id";
String accessToken = "token";
try {
// Load the JDBC driver class
Class.forName("com.databricks.driver.Driver");
Properties connectionProperties = new Properties();
// Set the necessary properties for the connection
connectionProperties.setProperty("user", "token");
connectionProperties.setProperty("PWD", accessToken);
// Create a connection using the JDBC URL and access token
Connection conn = DriverManager.getConnection(jdbcUrl, connectionProperties);
// Create a statement
Statement stmt = conn.createStatement();
// Get the list of namespaces (databases)
String showNamespacesQuery = "SHOW NAMESPACES";
ResultSet namespacesResult = stmt.executeQuery(showNamespacesQuery);
System.out.println("Namespaces (Databases):");
while (namespacesResult.next()) {
String namespace = namespacesResult.getString(1);
System.out.println(namespace);
}
namespacesResult.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
I can get 'default' as result.
After I changed the connection string to database=default
String jdbcUrl = "jdbc:spark://your-databricks-workspace-url:443;transportMode=http;ssl=true;httpPath=sql/protocolv1/o/your-org-id/your-workspace-id;database=default";
It will throw error:
[SparkJDBCDriver](500051) ERROR processing query/statement. Error Code: 0, SQL state: TStatus(statusCode:ERROR_STATUS, infoMessages:[*org.apache.hive.service.cli.HiveSQLException:Configuration database is not available.:48:47