| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 426 人关注过本帖
标题:求助,NULL异常
只看楼主 加入收藏
mickboy
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2007-1-11
收藏
 问题点数:0 回复次数:1 
求助,NULL异常

求助,NULL异常
package example_2;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;

public class UserServlet2 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";

//Initialize global variables
public void init() throws ServletException {
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String password=null;
String firstname=null;
String lastname=null;
String age=null;
String gender=null;
ServletContext context=this.getServletContext();
Object obj=context.getAttribute("UserID");
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>CustomerDetails</title></head>");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:test","sa","sa");
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("select *from CustomerRegistration where UserID='"+obj.toString()+"'");//空引用,我实在是找不出来原因
boolean flag=rs.next();
if(flag==true){
password=rs.getString(2);
firstname=rs.getString(3);
lastname=rs.getString(4);
gender=rs.getString(5);
age=rs.getString(6);
}else{
out.println("<font color=red size=7>登陆失败</font>");
}
}catch(java.sql.SQLException ex){
out.println("<font color=red size=7>"+ex.toString()+"</font>");
}catch(ClassNotFoundException e){
out.println("类未找到异常"+e.toString());
}
out.println("<body bgcolor=\"#ffffff\">");
out.println("<h1 align=center>欢迎来到 Shop Stop</h1>");
out.println("<table width=80% border=0 align=center>");
out.println("<tr align=center valign=top>");
out.println("<td colspan=2><h1><em><strong>客户详细信息</strong></em></h1></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td width=25%><span><strong>用户ID:</strong></span></td>");
out.println("<td width=75%><span>"+obj.toString()+"</span></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td><span><strong>口令:</strong></span></td>");
out.println("<td><span>"+password+"</span></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td><span><strong>全名:</strong></span></td>");
out.println("<td><span>"+firstname+"</span></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td><span><strong>性别:</strong></span></td>");
out.println("<td><span>"+gender+"</span></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td><span><strong>年龄:</strong></span></td>");
out.println("<td><span>"+age+"岁</span></td>");
out.println("</tr>");
out.println("</table>");
out.println("</body>");
out.println("</html>");
out.close();
}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}

//Clean up resources
public void destroy() {
}
}

搜索更多相关主题的帖子: NULL 
2007-06-02 21:39
风月_无边
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:60
帖 子:2960
专家分:652
注 册:2007-1-19
收藏
得分:0 
首先确定连接是否建立!

我的网站 http://www.
2007-06-02 21:58
快速回复:求助,NULL异常
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034950 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved