两次调用ResultSet时报错!

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了两次调用ResultSet时报错!相关的知识,希望对你有一定的参考价值。

小弟想把两个表相关的内容放到一个新表中(不用2个表的关联)!两次用到了ResultSet:
ResultSet rt=stmt.executeQuery("select * from user where id='"+id+"'");
rt.next();
ResultSet rs=stmt.executeQuery("select * from login where email='"+email+"'");
rs.next();
stmt.executeUpdate("INSERT INTO temporary(name,cost,handset)VALUES('"+rt.getString("name")+"','"+rt.getString("cost")+"','"+rs.getString("handset")+"')");
报出了org.apache.jasper.JasperException和java.lang.NullPointerException错误!请好心的大哥(大姐)帮忙解决以下吧!小弟非常感谢!

这个错 是说 rt.getString("name") 或者
rt.getString("cost") 或者
rs.getString("handset") 这个几个结果集 不能得到数据
rt.next(); 改成
if(rt.next())

ResultSet rs=stmt.executeQuery("select * from login where email='"+email+"'");
if(rs.next())
stmt.executeUpdate("INSERT INTO temporary(name,cost,handset)VALUES('"+rt.getString("name")+"','"+rt.getString("cost")+"','"+rs.getString("handset")+"')");

参考技术A 你要使用的对象为NULL
仔细检查一下

自定义时间选择器调用时报错

FATAL EXCEPTION: main
Process: droid.gdhktech.com.pubhealthdoc, PID: 8948
java.lang.RuntimeException: Unable to start activity ComponentInfo{droid.gdhktech.com.pubhealthdoc/droid.gdhktech.com.pubhealthdoc.ui.acti.MainActivity}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:562)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:282)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.widget.PopupWindow.invokePopup(PopupWindow.java:1104)
at android.widget.PopupWindow.showAtLocation(PopupWindow.java:933)
at android.widget.PopupWindow.showAtLocation(PopupWindow.java:897)
at droid.gdhktech.com.pubhealthdoc.ui.widge.BottomPopupWindow.show(BottomPopupWindow.java:85)
at droid.gdhktech.com.pubhealthdoc.ui.acti.MainActivity.initData(MainActivity.java:42)
at cn.droidlover.xdroid.base.XActivity.onCreate(XActivity.java:31)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

 

 

解决:不要直接在activity里面调用,要在OnClickListeners里面调用。

以上是关于两次调用ResultSet时报错!的主要内容,如果未能解决你的问题,请参考以下文章

ReactJs:PrivateRoute 组件被调用两次

java.lang.AbstractMethodError: Method com/mysql/jdbc/ResultSet.isClosed()Z is abstract 报错修改记录

自定义时间选择器调用时报错

springboot项目中调用jar包中的类时报错 — 没有注入类

springboot项目中调用jar包中的类时报错 — 没有注入类

安装MongoDB启动时报错‘发生系统错误2’的解决办法