我有下面的方法,它将接受两个参数-
final String userId- Primary Key for the database
final Collection<String> attributeNames- list of column names that I want to retrieve
下面是代码
public Map<String, String> getAttributes(final String userId, final Collection<String> attributeNames) {
//Below line doesn't works out the way I wanted
String query="SELECT" +attributeNames.toString()+ ", * from test where id = "+userId+ ";";
ResultSet result = CassandraDatastaxConnection.getInstance().getSession().execute(query);
for (Row rows: result){
System.out.println(rows.getString("key"));
}
return attributes;
}
举个例子,userId as 40
样品attributeNames
看起来像这样 -
[account, behavior, segmentation]
现在我需要生成与输入对应的 SQL。所以对于上面的例子,sql应该是这样的——
SELECT account, behavior, segmentation from test where id = "40";
如何从上述输入生成这样的 SQL?谢谢您的帮助。