cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Warehousing & Analytics
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

What is the difference between :443/default and Database=default in JDBC connection string

charlie_cai
New Contributor II

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

1 REPLY 1

Tharun-Kumar
Honored Contributor II
Honored Contributor II

@charlie_cai 

database is not a valid configuration parameter available in the jdbc string. You can use ConnCatalog and ConnSchema to provide this information.

This is also documented here - https://docs.databricks.com/en/integrations/jdbc-odbc-bi.html#:~:text=To%20specify%20the%20default%2....

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.