你的程序中某处对值为null的对象进行了某些操作
解决方案 »
- 请教struts2大问题
- 问一个比较菜的问题,JBoss和Tomcat URL过滤问题,谢谢大家了!
- 关于webwork标签iterator如何处理这个list中的对象的2个问题
- jsp新手要看什么书好
- 弹出页面只有一个关闭按扭,是怎么设置的?
- 请问Hibernate+Sturnts+Spring 多对多怎么实现 最好是能给个添加删除的例子
- Struts2 调用 hibernate 错误(在线等)
- 如何知道一个session变量的sessionId?在线等待。
- 关于JSP中JDBC conntion SQL SERVER写库的问题。
- 同样的$.ajax()调用两次,在IE8下只进入一次Action
- 请教:Java类中get和set方法必须是成对出现,缺一不可吗?
- 使用updateRow()时的运行错误,再线等待。
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%><html>
<head>
<title>查询结果</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body bgcolor="#CCCCCC" text="#000000">
<div align="center">
<p> </p>
<p> <font size="4"> <b> 成绩查询结果 </b></font></p>
<p> </p>
<p>
<font size="2"><b>
<%
int n;
String temp1=new String();
String temp2=new String();
temp1=request.getParameter("txtname");
temp2=request.getParameter("txtpassword");
n=temp1.length()*temp1.length();
%>
<%
if(n==0){
%>
<p>2请输入正确的姓名和密码。</p>
<p><a href="student.htm">返回</a></p>
<%
}
else{
String tempname=new String();
String tempclass=new String();
String tempsex=new String();
String tempage=new String();
String tempnum=new String();
String tempenglish=new String();
String tempchinese=new String();
String tempmath=new String();
String tempsum=new String();
String temporder=new String();
String url=new String();
url="jdbc:odbc:student";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student");
java.sql.Statement stmt=con.createStatement();
String SQL=new String();
%>
<%
SQL="SELECT * FROM stu WHERE name='"+temp1+"'and password='"+temp2+"'";
ResultSet rs=stmt.executeQuery(SQL);
%>
<%
if(rs.next()){
tempname=rs.getString("name");
tempclass=rs.getString("class");
tempnum=rs.getString("number");
tempsex=rs.getString("sex");
tempage=rs.getString("age");
rs.close();
%>
<%
SQL="SELECT * FROM res WHERE number="+tempnum;
ResultSet rs1=stmt.executeQuery(SQL);
if(rs1.next()){
tempenglish=rs1.getString("english");
tempchinese=rs1.getString("chinese");
tempmath=rs1.getString("math");
tempsum=rs1.getString("sum");
temporder=rs1.getString("order");
}
rs1.close();
%>
<table width="600" border="2"
cellspacing="2" cellpadding="2" bordercolorlight="#000000"
bordercolordark="#000000">
<tr bordercoler=#000000">
<td height="30" width="100">
姓名:</td>
<td height="30" width="200">
<%=tempname%></td>
<td height="30" width="100">
学号:</td>
<td height="30" width="200">
<%=tempnum%></td>
</tr>
<tr bordercoler=#000000">
<td height="30" width="100">
性别:</td>
<td height="30" width="200">
<%=tempsex%></td>
<td height="30" width="100">
年龄:</td>
<td height="30" width="200">
<%=tempage%></td>
</tr>
<tr bordercoler=#000000">
<td height="31" width="100">
班级:</td>
<td height="31" width="200">
<%=tempclass%></td>
<td height="31" width="100"> </td>
<td height="31" width="200"> </td>
</tr>
<tr bordercoler=#000000">
<td height="30" width="100">
英语:</td>
<td height="30" width="200">
<%=tempenglish%></td>
<td height="30" width="100">
语文:</td>
<td height="30" width="200">
<%=tempchinese%></td>
</tr>
<tr bordercoler=#000000">
<td height="30" width="100">
数学:</td>
<td height="30" width="200">
<%=tempmath%></td>
</tr>
<tr bordercoler=#000000">
<td height="30" width="100">
总分:</td>
<td height="30" width="200">
<%=tempsum%></td>
<td height="30" width="100">
排名:</td>
<td height="30" width="200">
<%=temporder%></td>
</tr>
</table>
<%}
else{%>
<p>请正确输入姓名和密码。</p>
<p><a href="student.htm">
返回</a></p>
<%
}
stmt.close();
con.close();
}
%>
</b>
</font>
</div>
</body>
</html>
String temp1=new String();
String temp2=new String();
temp1=request.getParameter("txtname");
temp2=request.getParameter("txtpassword");
n=temp1.length()*temp1.length();这里需要在对temp1和temp2赋值之前判断是否为null,否则当为null时下面的length方法就会出现空指针错误。
SQL="SELECT * FROM res WHERE number="+tempnum;
ResultSet rs1=stmt.executeQuery(SQL);
if(rs1.next()){
tempenglish=rs1.getString("english");
tempchinese=rs1.getString("chinese");
tempmath=rs1.getString("math");
tempsum=rs1.getString("sum");
temporder=rs1.getString("order");
}
不要用
select * from.....
直接写出字段名比较好。
也许以后经常要碰到。切记!