Cassandra:无论数据类型如何,如何获取列数据的字符串值

Cassandra : How to get the String value of column data irrespective of datatype

我正在尝试从 com.datastax.driver.core.ResultSet 中获取结果并打印出来:

ResultSet results = getSession().execute("Select * from test.table"); //getsession returns a session
int numcols = results.getColumnDefinitions().size();
for ( Row row : results ) {
    for (int colIndex = 0; colIndex < numcols; colIndex++) {
           System.out.println("data: " + row.getString(colIndex));
     }
}

row.getString(colIndex) 在数据类型不是 String 的情况下抛出异常。无论数据类型是什么,我将如何获得字符串数据?

此代码将打印每列的类型和值

ResultSet results = getSession().execute("Select * from test.table");    
int numcols = results.getColumnDefinitions().size();
for ( Row row : results ) {
   for (int colIndex = 0; colIndex < numcols; colIndex++) {
         System.out.println("Type : "+row.getColumnDefinitions().getType(colIndex));
         Class c = row.getColumnDefinitions().getType(colIndex).asJavaClass();
         if(c == Integer.class) {
              System.out.println("Data :" + row.getInt(colIndex));
         }
         //similar for other type
   }
}