简体   繁体   English

无法使用 jdbc 驱动程序连接 Cassandra

[英]Unable to connect Cassandra using jdbc driver

Hi I am trying to connect with Cassandra using jdbc driver.嗨,我正在尝试使用 jdbc 驱动程序与 Cassandra 连接。 I am getting the following exception.我收到以下异常。

java.sql.SQLNonTransientConnectionException: Connection url must specify a host, e.g., jdbc:cassandra://localhost:9170/Keyspace1
    at org.apache.cassandra.cql.jdbc.Utils.parseURL(Utils.java:190)
    at org.apache.cassandra.cql.jdbc.CassandraDriver.connect(CassandraDriver.java:85)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.sub.cas.CqlJdbcTestBasic.main(CqlJdbcTestBasic.java:14)

My cassandra server is running fine and can be accessed from cql shell in windows 10 OS.我的 cassandra 服务器运行良好,可以从 Windows 10 操作系统中的 cql shell 访问。

This is the java class that I have written.这是我写的java类。

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class CqlJdbcTestBasic {
public static void main(String[] args) {
    Connection con = null;
    try {
        Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
        con = DriverManager.getConnection("jdbc:cassandra:/root/root@localhost:9160/hr");

        String query = "SELECT empid, emp_first, emp_last FROM User WHERE empid = 1";

        Statement stmt = con.createStatement();
        ResultSet result = stmt.executeQuery(query);

        while (result.next()) {
            System.out.println(result.getString("empid"));
            System.out.println(result.getString("emp_first"));
            System.out.println(result.getString("emp_last"));
        }

    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            con = null;
        }
    }
}
}

I have gathered my jars from this url :: https://code.google.com/archive/a/apache-extras.org/p/cassandra-jdbc .我从这个网址收集了我的罐子 :: https://code.google.com/archive/a/apache-extras.org/p/cassandra-jdbc Unable to find any possible solution.无法找到任何可能的解决方案。 Please help.请帮忙。

Please, check if you have two slashes before your user name.请检查您的用户名前是否有两个斜线。 According to根据

http://www.dbschema.com/cassandra-jdbc-driver.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM