我有一个返回类型为 java.lang.object
的方法,我想将它转换为 int
。我尝试了以下代码:
oldComment.get("count");
我想要把返回一个java.lang.object
的方法结果转换成整数。我尝试了以下代码:
(Integer)oldComment.get("count");
Integer.valueOf(oldComment.get("count"));
Integer.parseInt(oldComment.get("count"));
con = Base.connection();
String query = "UPDATE COMMENT SET LIKES = ? WHERE POST_ID = ?";
PreparedStatement pst = con.prepareStatement(query);
pst.setObject(1, (Integer.parseInt(oldComment.get("likes").toString())) + Integer.valueOf(rateComment.getCount()));
pst.setString(2, rateComment.getPost_id());
int k = pst.executeUpdate();
这是导致问题的代码:
(Integer.parseInt(oldComment.get("likes").toString()))
。
错误堆栈跟踪:
[qtp25844331-17] ERROR spark.http.matching.GeneralError -
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at com.soul.seeker.serviceImpl.CommentRatingServiceImpl.rateComment(CommentRatingServiceImpl.java:50)
at com.soul.seeker.Application.lambda$main$12(Application.java:161)
at spark.ResponseTransformerRouteImpl$1.handle(ResponseTransformerRouteImpl.java:47)
at spark.http.matching.Routes.execute(Routes.java:61)
at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:130)
at spark.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:50)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
at org.eclipse.jetty.server.Server.handle(Server.java:517)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:261)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
at java.lang.Thread.run(Thread.java:745)
上述方法都无法解决问题。我应该如何进行转换?
java.lang.Object
。 - kittuInteger
,以及为什么。 - Arnaud