2013-02-22 72 views
4

當我使用卡桑德拉-jdbc我得到錯誤java.sql.SQLSyntaxErrorException惰性數據轉換成表:無法解析「ANI」作爲十六進制字節插入錯誤

連在localhost來測試集羣:9160。 [cqlsh 2.3.0 | Cassandra 1.2.0 | CQL規範3.0.0 |節儉協議19.35.0] 使用CQL3創建表

cqlsh:testkeyspace> create columnfamily login(
       ... key varchar primary key, 
       ... name varchar, 
       ... password varchar); 


package com.bsmart; 

import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 

public class InsertCass { 

     public static void main(String[] args) { 
      try 
      { 
       Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver"); 
       Connection con =DriverManager.getConnection("jdbc:cassandra://localhost:9160/testkeyspace"); 

       String qry = "INSERT INTO login (KEY, name, password) VALUES ('t', 'ani','agrawal');"; 
       PreparedStatement smt = con.prepareStatement(qry); 
       smt.execute(); 
       // int i=smt.executeUpdate(); 

       System.out.println("records inserted>>>>"); 



      } 
      catch(Exception e) 
      { 
       System.out.println(" error: "+e.getMessage()); 
       e.printStackTrace(); 
      } 

    } 

但ERROR-

log4j:WARN No appenders could be found for logger (org.apache.cassandra.cql.jdbc.CassandraDriver). 
log4j:WARN Please initialize the log4j system properly. 
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 
java.sql.SQLSyntaxErrorException: cannot parse 'ani' as hex bytes 
    at org.apache.cassandra.cql.jdbc.CassandraPreparedStatement.doExecute(CassandraPreparedStatement.java:155) 
    at org.apache.cassandra.cql.jdbc.CassandraPreparedStatement.execute(CassandraPreparedStatement.java:191) 
    at com.bsmart.InsertCass.main(InsertCass.java:18) 
error: cannot parse 'ani' as hex bytes 

請幫助我。 謝謝

+0

適當的版本不知道......似乎問題用U用來創建表的DDL語句。你必須正確指定驗證類和所有.. – 2013-02-22 12:03:15

回答

1

您需要創建name列爲textvarchar。您收到的錯誤表明它創建爲blob

+0

我創建名稱列爲varchar。但錯誤沒有解決。 cqlsh:testkeyspace>創建columnfamily登錄( ... key varchar主鍵, ... name varchar, ... password varchar); – Rani 2013-02-25 05:35:32

0

自己有這個問題,但在我的情況下,它是從double類型。

在蟒蛇的情況下,確保指定定製列表

cql.connect(cluster_address, port, keyspace, cql_version='3.1.1')