By using AWS re:Post, you agree to the Terms of Use
/Can't access created keyspace/table via Java API/

Can't access created keyspace/table via Java API

0

I have created a keyspace and tables via the AWS Console, and inserted some sample data via the console CQL editor, but I can't appear to access them via the Java API.

I have successfully configured the driver/session and ran the sample program as mentioned in the developer docs( ResultSet rs = session.execute("select * from system_schema.keyspaces");).

But when I attempt to run a simple select statement that works in the Console CQL editor I get a datastax error:
Exception in thread "main" com.datastax.oss.driver.api.core.servererrors.InvalidQueryException: unconfigured table table_keyspace.table_name

My searching leads me to believe that error message means the keyspace/table don't exist.

Is there something obvious I’m missing? If I can connect via the sample program, why can't I connect via the API?

Here is the config/code for reference:

datastax-java-driver {

basic.contact-points = \[ "cassandra.us-east-2.amazonaws.com:9142"]  
advanced.auth-provider{  
    class = PlainTextAuthProvider  
    username = "xxxxxxx"  
    password = "xxxxxxxx"  
}  
basic.load-balancing-policy {  
    local-datacenter = "us-east-2"  
}  

advanced.ssl-engine-factory {  
    class = DefaultSslEngineFactory  
    truststore-path = "./src/main/resources/key/cassandra_truststore.jks"  
    truststore-password = "xxxxxxx"  
  }  

  metadata {  
      schema.enabled = false  
      token-map.enabled = false  
    }  
    connection.warn-on-init-error = false  

}

public class CassandraTestClass {

**public static void main( String\[] args )**  
**{**  
    **//Use DriverConfigLoader to load your configuration file**  
    **DriverConfigLoader loader = DriverConfigLoader.fromClasspath("application.conf");**  
    **try (CqlSession session = CqlSession.builder()**  
            **.withConfigLoader(loader)**  
            **.build()) {**  

        **ResultSet rs = session.execute("SELECT ** FROM test_keyspace.test_table_name;");*  
        **Row row = rs.one();**  
        **System.out.println(row.getString("id"));**  
    **}**  
**}**  

}

Edited by: lkalland on Dec 23, 2020 10:21 AM

Edited by: lkalland on Dec 23, 2020 10:24 AM

Edited by: lkalland on Dec 23, 2020 10:27 AM

Edited by: lkalland on Dec 23, 2020 10:28 AM

asked a year ago1 views
1 Answers
0

I'm an idiot. Was connecting to wrong region.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions