查询数据库问题
本人刚学javaweb,属于菜鸟,问个问题。我做了一个jsp网页,里面有个表单,提交到本网页的。通过向表单里填写信息,查询数据库。可是出错报出异常,以下是代码。
<body>
<table align="center" bgcolor="FF9999" border=1 width="500">
<form name="form1" method="get" action="zhengti.jsp">
<tr>
<td align="center">数据查询</td>
<td><select name="select">
<option value="学号" selected>学号</option>
<option value="姓名">姓名</option>
<option value="班级">班级</option>
</select></td>
<td><input type="text" size=10 name="t1"></td>
<td><input type="submit" value="查询" name="cha"></td>
</tr>
</form>
</table>
<%! String odbcQuery; %>
<%
String leibie=request.getParameter("select");
if(leibie!=null)
{
leibie=new String(leibie.getBytes("ISO-8859-1"));
}
String chaxun=request.getParameter("t1");
if(chaxun!=null)
{
chaxun=(new String(chaxun.getBytes("ISO-8859-1"))).trim();
}
if(leibie.equals("学号"))
{
odbcQuery="Selcet* form glz where 学号 like'%"+chaxun+"%'";
}
else if(leibie.equals("姓名"))
{
odbcQuery="Selcet* form glz where 姓名 like'%"+chaxun+"%'";
}
else if(leibie.equals("班级"))
{
odbcQuery="Select* form glz where 班级 like'%"+chaxun+"%'";
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDrier");
}catch(ClassNotFoundException e){}
try
{
Connection con=DriverManager.getConnection("jdbc:odbc:as");
Statement sql=con.createStatement();
ResultSet rs=sql.executeQuery(odbcQuery);
%>
<table align="center" border=1 width="500">
<tr>
<td bgcolor="0099FF" align="center">学号</td>
<td bgcolor="0099FF" align="center">姓名</td>
<td bgcolor="0099FF" align="center">性别</td>
<td bgcolor="0099FF" align="center">年龄</td>
<td bgcolor="0099FF" align="center">班级</td>
</tr>
<%
while(rs.next())
{
%>
<tr>
<td><%rs.getInt("学号");%></td>
<td><%rs.getString("姓名");%></td>
<td><%rs.getString("性别");%></td>
<td><%rs.getInt("年龄");%></td>
<td><%rs.getString("班级");%></td>
</tr>
<% }
rs.close();
sql.close();
con.close();
}catch(SQLException ee){}
%>
</table>
</body>
以下是异常
org.apache.jasper.JasperException: An exception occurred processing JSP page /zhengti.jsp at line 44
41: <%!
42: String odbcQuery;
43: %>
44: <% String leibie=request.getParameter("select");
45: if(leibie!=null)
46: {
47: leibie=new String(leibie.getBytes("ISO-8859-1"));
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:554)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:319)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NullPointerException
org.apache.jsp.zhengti_jsp._jspService(zhengti_jsp.java:114)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:319)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
请问下哪里出现错误了,我看是空指针异常,可是我的变量应该都获取到了呀~求解释~
[解决办法]
设置断点,看哪个对象是空的没获取到
[解决办法]
Select* form glz where 班级 like'%"+chaxun+"% 里面是from
[解决办法]
String leibie=request.getParameter("select");
貌似这个没有获取到,为空啊
[解决办法]
3楼 好眼力啊
[解决办法]
firbug + debug server 一定能出来
我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.myexception.cn/j2se/33144.html