Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        6年前关闭。
                    
                
        

我在cassandra表中插入了一组数据。但是我在其中得到了不匹配的列名/值。我正在发布代码以及表结构

public static void aMethod2FromData(DetailsVO detailsVO) {

    System.out.println(detailsVO.getA_no());

    StringBuilder sb = new StringBuilder();

    int num = (int) (Math.random() * 8847);
    int radar = (int) (Math.random() * 847);
    sb.append(
    "INSERT INTO CALL_RATIO_ANALYSYS (A_NO,JAN,FEB,MAR,APR,MAY,JUNE,JULY,AUG,SEP,OCT,NOV,DEC,RADAR_VOICE,RADAR_SMS,RADAR_MMS,RADAR_GPRS,RADAR_OTHER,MMS_INCOMING,MMS_OUTGOING,VOICE_INCOING,VOICE_OUTGOING,SMS_INCOMING,SMS_OUTGOING,GPRS_SOCIAL,GPRS_MAIL,GPRS_GOOGLE,GPRS_ENTERTAINMENT,GPRS_BUSINESS)")
            .append("VALUES(");



        sb.append("'").append(detailsVO.getA_no()).append("',");
        //calculation for Jan to dec
        sb.append("'").append(num).append("',");
        sb.append("'").append(num).append("',");
        sb.append("'").append(num).append("',");
        sb.append("'").append(num).append("',");
        sb.append("'").append(num).append("',");
        sb.append("'").append(num).append("',");
        sb.append("'").append(num).append("',");
        sb.append("'").append(num).append("',");
        sb.append("'").append(num).append("',");
        sb.append("'").append(num).append("',");
        sb.append("'").append(num).append("',");
        sb.append("'").append(num).append("',");
        //end here
        //start calculation of radar
        sb.append("'").append(radar).append("',");
        sb.append("'").append(radar).append("',");
        sb.append("'").append(radar).append("',");
        sb.append("'").append(radar).append("',");
        sb.append("'").append(radar).append("',");
        //ends here
        //mms incoming
        sb.append("'").append(radar).append("',");
        sb.append("'").append(radar).append("',");
        //ends here
        //voice incoming outgoing
        sb.append("'").append(radar).append("',");
        sb.append("'").append(radar).append("',");
        //end here
        //sms incoming outgoing
        sb.append("'").append(radar).append("',");
        sb.append("'").append(radar).append("',");
        //ends here
        //gprs calculation
        sb.append("'").append(radar).append("',");
        sb.append("'").append(radar).append("',");
        sb.append("'").append(radar).append("',");
        sb.append("'").append(radar).append("')");
        //ends here
        System.out.println(sb.toString());
        String cql = sb.toString();
        session.execute(cql);
    }


这是表结构

CREATE TABLE CALL_RATIO_ANALYSYS(
A_NO TEXT,
JAN  TEXT,
FEB  TEXT,
MAR  TEXT,
APR  TEXT,
MAY  TEXT,
JUNE TEXT,
JULY TEXT,
AUG  TEXT,
SEP  TEXT,
OCT  TEXT,
NOV  TEXT,
DEC  TEXT,
RADAR_VOICE TEXT,
RADAR_SMS TEXT,
RADAR_MMS TEXT,
RADAR_GPRS TEXT,
RADAR_OTHER TEXT,
MMS_INCOMING TEXT,
MMS_OUTGOING TEXT,
VOICE_INCOMING TEXT,
VOICE_OUTGOING TEXT,
SMS_INCOMING TEXT,
SMS_OUTGOING TEXT,
GPRS_SOCIAL TEXT,
GPRS_MAIL TEXT,
GPRS_GOOGLE TEXT,
GPRS_ENTERTAINING TEXT,
GPRS_BUSINESS TEXT,
PRIMARY KEY(A_NO)
);


我无法理解该列与数据不匹配的地方,请帮助

最佳答案

我建议您使用准备好的语句。这不是直接解决问题的方法,但您不应构建这样的CQL语句。它效率低下,代码变得一团糟。可能会有逗号或其他缺失,但是尝试检查代码的语法比仅使用准备好的语句重写要花费更多的时间:

PreparedStatement statement = session.prepare("INSERT INTO CALL_RATIO_ANALYSYS (A_NO,JAN,FEB,MAR,APR,MAY,JUNE,JULY,AUG,SEP,OCT,NOV,DEC,RADAR_VOICE,RADAR_SMS,RADAR_MMS,RADAR_GPRS,RADAR_OTHER,MMS_INCOMING,MMS_OUTGOING,VOICE_INCOING,VOICE_OUTGOING,SMS_INCOMING,SMS_OUTGOING,GPRS_SOCIAL,GPRS_MAIL,GPRS_GOOGLE,GPRS_ENTERTAINMENT,GPRS_BUSINESS) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
BoundStatement boundStatement = statement.bind(detailsVO.getA_no(), num, num, num, num, num, num, num, num, num, num, num, num, radar, radar, radar, radar, radar, radar, radar, radar, radar, radar, radar, radar, radar, radar, radar);
session.execute(boundStatement);


保留准备好的语句,然后重新使用它。

编辑,所以这里的真正问题是您缺少最后一个参数的值。如果错误消息表明您输入了错误的数值,则对数值进行计数会有所帮助。

关于java - 如何解决cassandra中不匹配的列名/值? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20973513/

10-10 16:41