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