弄了好几天,问题还没解决,数据库NullPointerException问题

youkuxiaobin 2010-06-02 08:48:12
错误代码org.apache.jasper.JasperException: Exception in JSP: /updateShow.jsp:40

37: else
38: {
39: a=Integer.parseInt(temp1);
40: rs.updateInt(2,a);
41: }
42:
43: a2=request.getParameter("chinesegrade");


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause

java.lang.NullPointerException
sun.jdbc.odbc.JdbcOdbcBoundCol.setRowValues(Unknown Source)
sun.jdbc.odbc.JdbcOdbcResultSet.updateInt(Unknown Source)
org.apache.jsp.updateShow_jsp._jspService(updateShow_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.26 logs.
...全文
206 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
ffscool 2010-06-02
  • 打赏
  • 举报
回复
╮(╯▽╰)╭。。这个问题我也正研究(⊙o⊙)?
coolwzjcool 2010-06-02
  • 打赏
  • 举报
回复
一步一步调试,很容易弄出来,,,

页面上输入out.print(value);
fei1703 2010-06-02
  • 打赏
  • 举报
回复
1。创建语句的时候,应加上可更新的参数。
Statement stmt = con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
2。执行查询后应用rs.next()取得行数据
3。执行rs.updateRow()真正执行数据库更新。
storm_1984 2010-06-02
  • 打赏
  • 举报
回复
if(temp1==null && !"".equals(temp1))
{
a4="100";
}
else{
a=Integer.parseInt(a4);
rs.updateInt(5,a);
}
这样试试
闭目鱼 2010-06-02
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 ronniegxq 的回复:]
String aa="SELECT * FROM Student WHERE NAME="+"\'"+name+"\'";
con=DriverManager.getConnection("jdbc:odbc:aaa","sa","");
sql=con.createStatement();
rs=sql.executeQuery(aa);


抽出的结果集为null吧
[/Quote]


对!也可以先判断rs是否有查处数据
闭目鱼 2010-06-02
  • 打赏
  • 举报
回复
把这几个都初始为
String temp1="0";
String a2="0";
String a3="0";
String a4="0";

rs.updateInt(“列名”,“值”);
ronniegxq 2010-06-02
  • 打赏
  • 举报
回复
String aa="SELECT * FROM Student WHERE NAME="+"\'"+name+"\'";
con=DriverManager.getConnection("jdbc:odbc:aaa","sa","");
sql=con.createStatement();
rs=sql.executeQuery(aa);


抽出的结果集为null吧
myhope88 2010-06-02
  • 打赏
  • 举报
回复
肯定是某个地方为空值或者变量未初始化才会这样子,仔细调试下应该不难解决的
joker_cd 2010-06-02
  • 打赏
  • 举报
回复
是否得到的ResultSet就是一个空对象呢
luojihaidao 2010-06-02
  • 打赏
  • 举报
回复
java.lang.NullPointerException
sun.jdbc.odbc.JdbcOdbcBoundCol.setRowValues(Unknown Source)

这里说值是空的。
Mars_Ma_OK 2010-06-02
  • 打赏
  • 举报
回复
引用:


这是ResultSet 的一段说明

A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, you can iterate through it only once and only from the first row to the last row. It is possible to produce ResultSet objects that are scrollable and/or updatable. The following code fragment, in which con is a valid Connection object, illustrates how to make a result set that is scrollable and insensitive to updates by others, and that is updatable. See ResultSet fields for other options.

而且就算在创建语句的时候,设置其为Updatable的了,得到的结果集也有可能是不可更新的。
例如 oracle 的 某个jdbc版本(具体版本忘了) 中就说明 如果 select 使用的是 select * 的话,得到的结果集也是不可更新的。

youkuxiaobin 2010-06-02
  • 打赏
  • 举报
回复
原代码是update.jsp
<%@page contentType="text/html;charset=gb2312" %>
<html>
<body>
<p > <h2 align="center"> 输入需要修改的内容其中是以姓名为索引的</h2></p>
<form action="updateShow.jsp" method="post">
<h4 align="center">姓名 <input type="text" name="name"></h4>
<br>
<h4 align="center">年龄 <input type="text" name="age"></h4>
<br>
<h4 align="center">语文成绩<input type="text"name="chinesegrade"></h4>
<br>
<h4 align="center">数学成绩<input type="text"name="mathgrade"></h4>
<br>
<h4 align="center">英语成绩<input type="text"name="enggrade"></h4>
<br>
<h4 align="center"><input type="submit" name="tijiao" value="提交确认"></h4>

</body>
</html>
updateShow.jsp
<%@page contentType="text/html;charset=gb2312" %>
<%@page import="java.sql.*"%>
<%@page import="java.io.*" %>
<html>
<body bgcolor="cyan">
<%

String temp1="aa";
String a2="bb";
String a3="cc";
String a4="dd";
int a=0;
String name=request.getParameter("name");
name=new String(name.getBytes("ISO-8859-1"));
Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
out.print("加载数据库失败");
}
try
{
String aa="SELECT * FROM Student WHERE NAME="+"\'"+name+"\'";
con=DriverManager.getConnection("jdbc:odbc:aaa","sa","");
sql=con.createStatement();
rs=sql.executeQuery(aa);
temp1=request.getParameter("age");
if(temp1==null)
{
temp1="100";
}
else
{
a=Integer.parseInt(temp1);
rs.updateInt(2,a);
}

a2=request.getParameter("chinesegrade");

if(a2==null)
{
a2="100";
}
else
{
a=Integer.parseInt(a2);
rs.updateInt(3,a);
}

a3=request.getParameter("mathgrade");
if(a3==null)
{
a3="100";
}
else{
a=Integer.parseInt(a3);
rs.updateInt(4,a);
}

a4=request.getParameter("enggrade");
if(temp1==null)
{
a4="100";
}
else{
a=Integer.parseInt(a4);
rs.updateInt(5,a);
}

out.print("<TABLE Border>");
out.print("<tr>");
out.print("<th width=100>"+"NAME");
out.print("<th width=100>"+"AGE");
out.print("<th width=100>"+"CHINESEGRADE");
out.print("<th width=100>"+"MATHGRADE");
out.print("<th width=150>"+"ENGGRADE");
out.print("</tr>");
aa="SELECT * FROM Student";
rs=sql.executeQuery(aa);
while(rs.next())
{
out.print("<tr>");
out.print("<td>"+rs.getString(1)+"</td>");
out.print("<td>"+rs.getInt(2)+"</td>");
out.print("<td>"+rs.getInt(3)+"</td>");
out.print("<td>"+rs.getInt(4)+"</td>");
out.print("<td>"+rs.getInt(5)+"</td>");
out.print("</tr>");
}
con.close();
sql.close();
}
catch(SQLException e1)
{
out.print("执行出错"+e1);
}

%>
</body>
</html>
a429003078 2010-06-02
  • 打赏
  • 举报
回复
晕 你咋能在rs.updateInt(3,a);
放两个参

JerryZhou_ 2010-06-02
  • 打赏
  • 举报
回复
你修改对象的信息是根据名字修改的么?而且我看起来你这个怎么都是在查询啊?没看到修改的语句?
tianzezhong 2010-06-02
  • 打赏
  • 举报
回复
temp1=request.getParameter("age");
if(temp1==null)
{
temp1="100";
}
改为
temp1=request.getParameter("age");
if(temp1==null || "".equals(temp1))
{
temp1="100";
}
试试看

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧