本文整理匯總了Java中com.datastax.driver.core.ResultSet.getColumnDefinitions方法的典型用法代碼示例。如果您正苦於以下問題:Java ResultSet.getColumnDefinitions方法的具體用法?Java ResultSet.getColumnDefinitions怎麽用?Java ResultSet.getColumnDefinitions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.ResultSet
的用法示例。
在下文中一共展示了ResultSet.getColumnDefinitions方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getColumnInfo
import com.datastax.driver.core.ResultSet; //導入方法依賴的package包/類
/**
* Returns a map with column name as key and column date type as value.
*
* The value might be as simple as "Boolean" or more complex like
* - "Set|Boolean"
* - "List|String"
* - "Map|String|Integer"
* these are cases when the data type is a container of primitive data types.
*
* @param tableName
* @return
* @throws DbException
*/
public Map<String, String> getColumnInfo(
String tableName ) throws DbException {
connect();
ResultSet results = session.execute("SELECT * FROM " + this.dbName + "." + tableName + " LIMIT 1");
Map<String, String> columnInfo = new HashMap<String, String>();
for (Definition columnDefinition : results.getColumnDefinitions()) {
DataType dataType = columnDefinition.getType();
String dataTypeName = dataType.getName().name();
if ("Set".equalsIgnoreCase(dataTypeName)) {
dataTypeName = dataTypeName + "|" + dataType.getTypeArguments().get(0);
} else if ("List".equalsIgnoreCase(dataTypeName)) {
dataTypeName = dataTypeName + "|" + dataType.getTypeArguments().get(0);
} else if ("Map".equalsIgnoreCase(dataTypeName)) {
dataTypeName = dataTypeName + "|" + dataType.getTypeArguments().get(0) + "|"
+ dataType.getTypeArguments().get(1);
}
columnInfo.put(columnDefinition.getName(), dataTypeName);
}
return columnInfo;
}
示例2: queryColumns
import com.datastax.driver.core.ResultSet; //導入方法依賴的package包/類
/**
* 描述: 查詢數據表字段名(key:字段名,value:字段類型名)
* 時間: 2017年11月15日 上午11:29:32
* @author yi.zhang
* @param table 表名
* @return
*/
public Map<String,String> queryColumns(String table){
try {
String sql = "select * from "+table;
ResultSet rs = session.execute(sql);
ColumnDefinitions rscd = rs.getColumnDefinitions();
int count = rscd.size();
Map<String,String> reflect = new HashMap<String,String>();
for (int i = 0; i < count; i++) {
String column = rscd.getName(i);
String type = rscd.getType(i).getName().name().toLowerCase();
reflect.put(column, type);
}
return reflect;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例3: createOutputRowMeta
import com.datastax.driver.core.ResultSet; //導入方法依賴的package包/類
void createOutputRowMeta(RowMetaInterface row, ResultSet rs) {
row.clear();
for (ColumnDefinitions.Definition d : rs.getColumnDefinitions()) {
logDebug(d.getName() + ',' + d.getType().getName() + ',' + d.getType().asFunctionParameterString());
ValueMetaBase valueMeta = new ValueMetaBase(d.getName(), Utils.convertDataType(d.getType()));
valueMeta.setTrimType(0);
row.addValueMeta(valueMeta);
}
}