JDBC Connection Cassandra

Source: Internet
Author: User
Tags cassandra

1. Database creation

Refer to the above Cassandra Getting started http://www.cnblogs.com/piaolingzxh/p/4197833.html

2, download the JDBC driver source code, build the JAR package

Source: Https://bitbucket.org/openscg/cassandra2-jdbc/src,

Of course, you can also use me to build good, address: http://download.csdn.net/detail/piaolingzxh/8320131

Note: Build with Maven,

3. Create a Java project using Java connection Cassandra, introduce these jar packages,

As for why to introduce these packages, you can refer to the downloaded JDBC Source code example, examples\runtest.sh

Jar Package Location Description: These two packages directly use the JDBC driver source under the Lib\ directory version, the other uses the Cassandra installation directory \lib under the version

Finally write the code, run

The code is as follows:

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 ();}}}
Run results

  

JDBC Connection Cassandra

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.