标签:
参考接上文cassandra入门 http://www.cnblogs.com/piaolingzxh/p/4197833.html
源码下载地址:https://bitbucket.org/openscg/cassandra2-jdbc/src,
当然,你也可以使用我构建好的,地址:http://download.csdn.net/detail/piaolingzxh/8320131
注:使用maven构建,
至于为啥要引入这些包,可以参看下载的jdbc源码示例,examples\runTest.sh
jar包位置说明:下图这两个包直接使用jdbc驱动源码下lib\目录里的版本,其他的使用cassandra安装目录\lib下的版本
代码如下:
import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; public class cassandra2 { public static void main(String[] a) { try { Class.forName("org.bigsql.cassandra2.jdbc.CassandraDriver"); Connection con = DriverManager .getConnection("jdbc:cassandra://127.0.0.1:9160/demo"); String query = "select * from demo.users"; Statement statement = con.createStatement(); ResultSet rs = statement.executeQuery(query); while (rs.next()) { System.out.print(rs.getString(1) + ":" + rs.getString(2) + "\t" + rs.getString(3) + "\t" + rs.getString(4) + "\t" + rs.getString(5) + "\t" + rs.getString(6) + "\t" + "\n"); } rs.close(); statement.close(); } catch (Exception e) { e.printStackTrace(); } } }
标签:
原文地址:http://www.cnblogs.com/piaolingzxh/p/4198228.html