java 使用 CQL jdbc 驱动程序时的连接字符串应该是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7688571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What should be the connection string while using CQL jdbc driver
提问by Tamil
What should be the connection string while using CQL jdbc driver?
使用 CQL jdbc 驱动程序时的连接字符串应该是什么?
Will I be able to find a proper/complete example for CQL using CQL JDBC driver in Java online?
我是否能够在线找到使用 Java 中的 CQL JDBC 驱动程序的 CQL 的正确/完整示例?
回答by libHyman
You'll need the cql jar from the apache site.
您将需要来自 apache 站点的 cql jar。
Here's the basic test I used after entering data via CLI (using sample from wiki):
这是我通过 CLI 输入数据后使用的基本测试(使用来自 wiki 的示例):
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/MyKeyspace");
String query = "SELECT KEY, 'first', last FROM User WHERE age=42";
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery(query);
while (result.next()) {
System.out.println(result.getString("KEY"));
System.out.println(result.getString("first"));
System.out.println(result.getString("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;
}
}
}
}
The user/password (root/root) seems arbitrary, just be sure to specify the Keyspace (MyKeyspace)
用户/密码 (root/root) 似乎是任意的,只要确保指定 Keyspace (MyKeyspace)
Note, 'first'is quoted in the query string because it is an CQL keyword
注意,'first'在查询字符串中被引用,因为它是一个 CQL 关键字
回答by Mahesh
You may also try using the cassandra-jdbc driver from http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/.
您也可以尝试使用http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/ 中的 cassandra-jdbc 驱动程序。
Alternatively using the following maven dependency:
或者使用以下 maven 依赖项:
<dependency>
<groupId>org.apache-extras.cassandra-jdbc</groupId>
<artifactId>cassandra-jdbc</artifactId>
<version>1.2.1</version>
</dependency>