I think I'm missing something in my code and my query. The code below gives me the following error (under the code).
I think it's because my data and table does not match but everything looks fine.
Could somebody help me?
public void insertFarmers( \
int id, String city, HashMap<String, String>the_farmers, List<String>foods, \
List<String> delivery, int food_id, int cost, HashMap<String, String>food_item, \
String unit) {
Cluster cluster = Cluster.builder()
.addContactPoints(serverIP)
.build();
try (Session session = cluster.connect("farm_db")) {
String insert_query = "INSERT INTO farmers \
(farmer_id, city, foods, delivery, the_farmers, \
food_id, cost, food_item, unit) \
VALUES (?,?,?,?,?,?,?,?,?)";
PreparedStatement pStatement = session.prepare(insert_query);
BoundStatement bStatement = pStatement.bind(id, city, the_farmers, foods, \
delivery, food_id, cost, food_item, unit);
session.execute(bStatement);
}
}
THE ERROR:
CodecNotFoundException: Codec not found for requested operation: \
[list<varchar> <-> java.util.HashMap]
farmer_id | city | cost | delivery | food_id | food_item | foods | the_farmers | unit
-----------+------+------+----------+---------+-----------+-------+-------------+------
Your schema doesn't match your code. You have a column with type list<text>
, but trying to insert map<text, text>