question

mgent avatar image
mgent asked Erick Ramirez edited

How can I connect to Astra using a JDBC connection?

I'd like to connect to Astra via JDBC, primarily using the jdbc driver used by IntelliJ which is com.dbschema.CassandraJdbcDriver.

Is there a way to do that?

astra db
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

smadhavan avatar image
smadhavan answered

@mgent, we don't have documentation on how to connect with DbSchema yet.

But if you weren't aware, there is an embedded cqlsh on Astra which you can access from your browser. For details, see Connecting to Astra databases using CQLSH.

If you'd prefer to use an IDE, there is also an embedded DataStax Studio available from your Astra DB. For details, see Connecting to databases with DataStax Developer Studio.

In the meantime, I'm going to reach out internally to the Cloud team at DataStax to see if they have instructions they can share. I will update my answer if I have anything new to add. Cheers!

p/s: You might also refer to the instructions provided here for connecting to Astra via Thia in the interim to see if you could leverage that to work with DbSchema.

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Erick Ramirez avatar image
Erick Ramirez answered r2_37154 commented

I'm not sure if it's possible but I'd be happy to help if you're willing to try. A few months ago, I managed to get the GoCQL driver (not a DataStax driver) to connect to Astra (see post #3753) with help from the DataStax Cloud team (the team behind Astra).

As I understand it, the DbSchema C* JDBC driver somehow implements the Java driver so we might be able to get it to connect to Astra with a bit of fiddling around.

Preparation

First up, you will need to download the secure-connect zipped bundle for your Astra database.

Unzip your copy of secure-connect-your_astra_db.zip which will contain the following files:

ca.crt
cert
cert.pfx
config.json
cqlshrc
identity.jks
key
trustStore.jks

The config.json file contains the following:

  • host - the contact point for the driver
  • port - the CQL client port
  • keyspace - Cassandra keyspace
  • trustStoreLocation - trustStore.jks is the truststore
  • trustStorePassword - your truststore password
  • keyStoreLocation - identity.jks is the keystore
  • keyStorePassword - your keystore password

SSL

Set the SSL parameters in the DbSchema.vmoptions as follows:

-Djavax.net.ssl.trustStore=/path/to/trustStore.jks
-Djavax.net.ssl.trustStorePassword=<trustStorePassword>
-Djavax.net.ssl.keyStore=/path/to/identity.jks
-Djavax.net.ssl.keyStorePassword=<keyStorePassword>

URL

Using the bits of information above, the JDBC URL format is:

jdbc:cassandra://host:port/keyspace

Using my config.json as an example:

{
  "host": "c39aeb05-b52a-49b2-96c2-41f3901969e8-us-east1.db.astra.datastax.com",
  "port": 31234,
  "keyspace": "community",
  ...
}

My JDBC URL would look like:

jdbc:cassandra://c39aeb05-b52a-49b2-96c2-41f3901969e8-us-east1.db.astra.datastax.com:31234/community

Please try it out and I'd be very interested to know how it goes. Cheers!

P.S. Oh and of course you'll need to provide the username and password. :)

2 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Erick Ramirez avatar image Erick Ramirez ♦♦ commented ·

@mgent just checking to see if you've had a chance to test this. Let me know either way. Cheers!

0 Likes 0 ·
r2_37154 avatar image r2_37154 Erick Ramirez ♦♦ commented ·

Hi, Erick! Got some direction from DataStax partner team about which JDBC Driver we should use at Liquibase: https://downloads.datastax.com/#odbc-jdbc-drivers. We have Liquibase working great with that driver. Here's how to do it: https://docs.liquibase.com/workflows/database-setup-tutorials/cassandra.html.

Now, we're working getting Liquibase working with Astra. I've set "javax.net.ssl.*" options and update my Liquibase properties to use the correct URL, username, password, keystore. (You're post above was great for that! Thanks!!!)

However, we're having some issues still.

Would you mind testing with the "Simba JDBC Driver for Apache Cassandra" (4.2) and see if that works for you like the other JDBC driver did?

Thanks!

Robert

1 Like 1 ·
gerardnico avatar image
gerardnico answered gerardnico published
Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.