Cassandra JDBC异常java.lang.ClassNotFoundException:org.apache.cassandra.cql.jdbc.CassandraDriver

时间:2018-11-23 11:25:27

标签: java cassandra

我正在使用cassandra 3.9(版本)。当我尝试如下所示的简单Java应用程序时,出现异常java.lang.ClassNotFoundException: org.apache.cassandra.cql.jdbc.CassandraDriver

我的密码

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;


public class DataPorting {
       public static void main(String[] args) throws Exception{ 
               Connection con = null;
                try {
                 Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
                 con = 
              DriverManager.getConnection("jdbc:cassandra://localhost:9042/ksfedemo");

                 String query = "SELECT * FROM customer  ";

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

                 while (result.next()) {
                  System.out.println(result.getString("name"));
                  System.out.println(result.getString("email_id"));
                  System.out.println(result.getString("mobile_number"));
                 }

                } catch (ClassNotFoundException e) {
                 e.printStackTrace();
                } catch (SQLException e) {
                 e.printStackTrace();
                } finally {
                 if (con != null) {
                  try {
                   con.close();
                  } catch (SQLException e) {
                   e.printStackTrace();
                  }
                  con = null;
                 }
                }



        }
}

例外

java.lang.ClassNotFoundException: org.apache.cassandra.cql.jdbc.CassandraDriver
                at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
                at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
                at java.lang.Class.forName0(Native Method)
                at java.lang.Class.forName(Class.java:264)
                at DataPorting.main(DataPorting.java:14)

请让我知道是否有解决方案!

0 个答案:

没有答案