高分求助!!!sql语句问题!
jsp如下,我的javabean没问题!
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " " %>
<%@ include file= "../include/set_china.jsp "%>
<jsp:useBean id= "query " class= "login.QueryBean " scope= "page ">
</jsp:useBean>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<link href= "../include/css.css " rel= "stylesheet " type= "text/css " />
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
</head>
<body>
<%
ResultSet rs=null;
String sql= "select a.txtnumber, a.txtname,b.course_name,b.course_mark,c.s_result from student_info as a join choose_course as c on a.txtnumber=c.student_id join course_info as b on c.s_course_id=b.course_id where a.txtnumber= '0467110054 ' ";
//String sql= "select * from student_info ";
try
{
//设置连接
String url= "jdbc:odbc:jwzx ";
query.setConnection( "sun.jdbc.odbc.JdbcOdbcDriver ",url, " ", " ");
//设置SQL语句
query.setQuerystatement(sql);
//得到查询结果
rs=query.getResult();
}
catch(SQLException e1)
{
out.print(e1);
}
while(rs.next())
{
out.print(rs.getString(1));
out.print(rs.getString(2));
}
%>
我把数据库导入sql后select a.txtnumber, a.txtname,b.course_name,b.course_mark,c.s_result from student_info as a join choose_course as c on a.txtnumber=c.student_id join course_info as b on c.s_course_id=b.course_id where a.txtnumber= '0467110054 '此语句正确!但是在jsp中就报错!我把sql改为String sql= "select * from student_info ";后就正确!迷茫中!
错误提示:
HTTP Status 500 -
--------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /My_jwzx/student/vew_chengji.jsp at line 32
29: {
30: out.print(e1);
31: }
32: while(rs.next())
33: {
34: out.print(rs.getString(1));
35: out.print(rs.getString(2));
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:555)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause
java.lang.NullPointerException
org.apache.jsp.My_005fjwzx.student.vew_005fchengji_jsp._jspService(vew_005fchengji_jsp.java:119)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:390)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.2 logs.
--------------------------------------------
Apache Tomcat/6.0.2
[解决办法]
很明显是空指针...我想你应该也知道
不过你说的改一下sql语句就正确...那应该是sql语句的问题了.
你可以debug试试看看究竟查询出来后是否为空
[解决办法]
看来是结果集为空,你再NEXT当然空指针
[解决办法]
while(rs.next())
{
out.print(rs.getString(1));
out.print(rs.getString(2));
}
写在try里面看看
[解决办法]
数据查出来的为空,看下SQL,将程序的SQL输出 然后放到数据库里先执行下,就知道哪里错了
[解决办法]
楼上说得对,rs.next()报空,很明显是ResultSet查出来是空的,所以rs=query.getResult()
是null,建议不要这样写。
[解决办法]
对 结果集是空的
[解决办法]
query.setQuerystatement(sql);//你这个方法是不是生成了一个结果集啊,你看一下你有没有在这个方法里面关了数据库的连接,or清空了resulet结果集
[解决办法]
首先,rs.next()抛异常,说明rs==null;
其次,rs == null,说明在连接数据库时以及提交数据时出现问题;
最后,如果用sql= "select * from student_info ",可以连接,说明上面那句sql有问题.你说在数据库中执行没有问题.
那么就很有可能是在写sql语句时,换行中没有把空格加上去.
比如说:select * from student where id = 1,这样一句sql语句写成:
select * from student(没有加空格,直接回车了)
where id =1;
那么系统就会认为:select * from studentwhere id = 1;
这样就会出现错误.
我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.myexception.cn/j2se/33144.html
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html