4

Not able to save java.sql.Date field using DBCollection.save()

Error : CodecConfigurationException: Can't find a codec for class java.sql.Date.

while insert() method has constructor having DBEncoder field.

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

But any kind of constructor for save() method.

Dev
  • 13,492
  • 19
  • 81
  • 174

1 Answers1

3

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 don't know when did you use java.sql.Date in your code, I suggest you should try to check if there are any Date variable that is update from SQL statement.

You should not have any problem if you use Mongo 2.x library, but since Mongo 3.x library, seems they removed the java.sql.Date support.

Dundee
  • 93
  • 1
  • 1
  • 5