Error saving java.sql.Date in MongoDB

Failed to save field java.sql.DateusingDBCollection.save()

Error: CodecConfigurationException: Cannot find codec for class java.sql.Date.

while the insert()method has a constructor with a DBEncoder field.

DBCollection.insert(List<? extends DBObject> documents, WriteConcern aWriteConcern, DBEncoder dbEncoder)

But any constructor for the method save().

+4
source share
1 answer

You need to change your Date object from java.sql.Date to java.util.Date

java.util.Date newDate = new Date(yourSqlDate.getTime());

if you do not know when you used java.sql.Date in your code, I suggest you try checking if there is any Date variable that is an update from the SQL statement.

, Mongo 2.x, , Mongo 3.x, , java.sql.Date.

+3

All Articles