我的JSP代码
<%@ page contentType="text/html; charset=gb2312" language="java"
import="java.sql.*" errorPage=""%>
<jsp:useBean id="conndbbean" scope="page" class="vote.vote_conn" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>网上调查</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style type="text/css">
<!--
.STYLE1 {color: #0000ff}
.STYLE2 {font-size: 14px}
-->
</style>
</head>
<%ResultSet rs = conndbbean.executeQuery("select * from vote");
%>
<body>
<div align="center" class="STYLE1">请您投票</div>
<form action="vote.jsp" method="post" enctype="multipart/form-data"
name="form1" target="_parent" id="form1">
<%try{while (rs.next()) {
%>
<tr>
<td><input type="radio" name="type" value=<%=rs.getString("id")%>><%=rs.getString("note")%></td>
</tr>
<%}
rs.close();}catch(NullPointerException e){out.println("NullPointerException ");}%>
<tr align="center">
<td><input type="submit" name="Submit" value="投票"></td>
</tr>
</form>
<p>查看投票</p>
</body>
</html>
bean的JAVA代码
package vote;
import java.sql.*;
public class vote_conn{
String sdbdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String sconnstr="jdbc:odbc:vote";
Connection connect=null;
ResultSet rs=null;
public vote_conn(){
try{
Class.forName(sdbdriver);
}catch(java.lang.ClassNotFoundException e){System.err.println(e.getMessage());
}
}
public ResultSet executeQuery(String sql){
try{
connect=DriverManager.getConnection(sconnstr,"","");
Statement stmt=connect.createStatement();
rs=stmt.executeQuery(sql);
}catch(SQLException ex){System.err.println(ex.getMessage());
}
return rs;
}
public int executeUpdate(String sql){
int result=0;
try{
connect=DriverManager.getConnection(sconnstr);
Statement stmt=connect.createStatement();
result=stmt.executeUpdate(sql);
}catch(SQLException ex){System.err.println(ex.getMessage());
}
return result;
} }
运行出现:
NullPointerException 投票
查看投票
请问怎么解决啊?
谢谢哦
[此贴子已经被作者于2006-8-9 22:20:17编辑过]
----------------解决方案--------------------------------------------------------
帮帮忙啊
----------------解决方案--------------------------------------------------------
把你的BEAN也帖出来
----------------解决方案--------------------------------------------------------
贴出来了
----------------解决方案--------------------------------------------------------
我感觉有两个地方有可能出现这个异常!
1.try{}catch(){}语句中应该包含执行SQL语句的代码,也就是执行SQL语句的代码放在try catch语句中。
2.就是catch(NullPointerException e){out.println("NullPointerException ");}这一句代码改成
catch(NullPointerExceptin e){e.printStackTrace();}试试。
在JSP页面中我没见过那样打印出异常信息的,也许是我自己见的少
----------------解决方案--------------------------------------------------------
可是怎么解决呢,唉
----------------解决方案--------------------------------------------------------
你应该把你抛出异常的信息帖出来,它会提示你哪一行出一异常
你再去找那一行,看看是不是哪个对象没有初始化
----------------解决方案--------------------------------------------------------