[英]MongoDb. Extracting integer from database. java.lang.Integer cannot be cast to java.lang.String
I am new to MongoDb. 我是MongoDb的新手。 I was trying to retreive data from the db.
我试图从数据库中检索数据。 Here is part of my code:
这是我的代码的一部分:
dbc(TABLENAME).find ( MongoDBObject (UID -> uid)).toList.foreach {s =>
val Rollno = s.getAs[String](ROLL).getOrElse ("?")
Apparently ROLL is set as integer, and I keep on getting the error java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String Is there an easy solution to get it? 显然ROLL设置为整数,并且我继续得到错误java.lang.ClassCastException:java.lang.Integer无法强制转换为java.lang.String是否有一个简单的解决方案来获取它?
How about getting it as an integer and then using toString? 如何将它作为整数然后使用toString?
dbc(TABLENAME).find ( MongoDBObject (UID -> uid)).toList.foreach {s =>
val Rollno = s.getAs[Int](ROLL).map(_.toString).getOrElse("?")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.