一个想了两天都没能解决的问题,望各位大侠指教!
一个关于用Jsp实现“会员”或是“企业”登陆的窗口:
这个是我作为数据库连接用的javabean:(经过之前的调试,应该是正常且可以运行的!)
package book.test;import java.sql.*;public class conn {
public Connection conn;
Statement statement;
ResultSet rs,rsSQL; public conn() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:ShopSystem","sa","sa");
statement = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
System.out.println("Connection OK!");
    }
    catch (Exception econn) {
     System.err.println("\nConnection Exception==============\n");
     System.err.println("SQLState:" + econn.getStackTrace());
     System.err.println("Message:" + econn.getMessage());
    }
}
public ResultSet execute(String _strSQL) {
 
try {
rsSQL = null;

if(conn != null) {
rsSQL = statement.executeQuery(_strSQL);
}
    }
    catch (SQLException ers) {
     System.err.println("\nResultSet Exception==============\n");
     System.err.println("SQLState:" + ers.getSQLState());
     System.err.println("Message:" + ers.getMessage());
    }
    return rsSQL;
}
}
我的一个JSP文件是作为登陆用的(文件名:login_do.jsp),里面有判断登陆用户的类型是属于“会员”还是“企业”的,但是在执行过程中出错了,不知道到底是哪里的错,请帮我看下,谢谢!
//************************************************************************** 这里面request获得的参数是从另一个jsp (LoginIndex.jsp) 页面的表单传递过来的!
         登陆用户名的输入框id为loginid
         登陆密码的输入框id为loginpw
         单选按钮 id为 type ,会员的value为 0 ,企业的value为 1//**************************************************************************
<%@ page contentType="text/html" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="loginbean" class="book.test.conn" scope="session"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<%
boolean loginAttempt = false;
boolean loginOK = false;
String errormessage = "请你登录";
String typetemp =null;
String type=(String)request.getParameter("logintype");//读取单选按钮判断是“会员”还是“企业”
//out.println(type);
if(type.equals("0"))//如果是“会员”
{
typetemp="Shop_UserInfo";//将用户表的表名赋值给一个变量typetemp
}else//如果是“企业”
{
typetemp="Shop_CompanyInfo";//将企业表的表名赋值给一个变量typetemp
}
if(request.getParameterValues("loginid") != null && request.getParameterValues("loginpw") != null)//判断用户名和密码是否为空
{
loginAttempt = true;//不为空则布尔型值为 true
}
//out.print(loginAttempt);
if(loginAttempt == true)//loginAttempt为 true 时,执行数据库的查询操作
{
String name = (String)request.getParameter("loginid");
String pw = (String)request.getParameter("loginpw");
String _strSQL = "select * from "+typetemp+" where LoginName = '"+name+"' and LoginPw = '"+pw+"'";
out.print(_strSQL); int rowcount =0; ResultSet rsSQL = loginbean.execute(_strSQL);//这里调用javabean的一个方法,执行数据库的查询操作!
//out.println(typetemp);
//out.println(name);
//out.println(pw);
try
{
while(rsSQL.next())//当数据库有查询的记录时,int值加一
{
rowcount++;

}
//out.print(rowcount+"5455555"); //******************************************************************************
//在捕捉异常时出项以下错误 }catch(Exception ex)
{
  out.println(ex.toString());//显示为java.lang.NullPointerException 
  out.println(ex.getMessage());//显示为 null
}
//*****************************************************************************
//out.println(rowcount+"13132131");
if(rowcount!=0)
{
session.setAttribute("name",name);
//response.sendRedirect("Login_success.jsp");
}else
{
session.setAttribute("name","");
//errormessage = "null";
//response.sendRedirect("Login_error.jsp?err=errormessage");

}
}
else
{
//errormessage = "ERROR";
//response.sendRedirect("Login_error.jsp?err=errormessage");
session.setAttribute("name","");
}

%>
</body>
</html>页面执行时出现一下错误:
提示我查询出现空指针:java.lang.NullPointerException 
但是我在数据库相应表中有记录啊!还有用SQL事件探查器查出是这种情况:
declare @P1 int
set @P1=0
declare @P2 int
set @P2=2
declare @P3 int
set @P3=8194
declare @P4 int
set @P4=0
exec sp_cursoropen @P1 output, N'select * from Shop_UserInfo where LoginName = ''admin'' and LoginPw = ''admin''', @P2 output, @P3 output, @P4 output
select @P1, @P2, @P3, @P4一般来说执行查询都不可能调用到存储过程的啊,可是这里执行查询时调用到了sp_cursoropen的系统存储过程,删除了该过程还是不行,到底是怎么回事呢,请指教,谢谢!还有,在tomcat5.0控制台中显示:
SQLState:S0002
Message:[Microsoft][ODBC SQL Server Driver][SQL Server]对象名'Shop_UserInfo'无效
对象名Shop_UserInfo是我存储会员信息的表!
在查询存储企业信息的表Shop_CompanyInfo时也会出错!