我在进行数据库登陆验证时出现下列异常信息:
type: Exception report
message :description :The server encountered an internal error () that prevented it from fulfilling this request.exception :java.lang.NullPointerException
loginwithdb.UserBean.validate(UserBean.java:15)
loginwithdb.loginServlet.doGet(loginServlet.java:25)
loginwithdb.loginServlet.doPost(loginServlet.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)note: The full stack trace of the root cause is available in the Apache Tomcat/5.0.27 logs.服务器是tomcat5.0,代码反复写了很多遍,应该没问题。不知是不是配置的问题,我的开发工具是JBuilder2005,在JDK和服务器里都添加了连接数据库的jar包,请高手给俺解答下,不胜感激!
type: Exception report
message :description :The server encountered an internal error () that prevented it from fulfilling this request.exception :java.lang.NullPointerException
loginwithdb.UserBean.validate(UserBean.java:15)
loginwithdb.loginServlet.doGet(loginServlet.java:25)
loginwithdb.loginServlet.doPost(loginServlet.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)note: The full stack trace of the root cause is available in the Apache Tomcat/5.0.27 logs.服务器是tomcat5.0,代码反复写了很多遍,应该没问题。不知是不是配置的问题,我的开发工具是JBuilder2005,在JDK和服务器里都添加了连接数据库的jar包,请高手给俺解答下,不胜感激!
解决方案 »
- Google map api v3 怎么画编码折线啊
- Ext得表单。求解答。。在线等!急!!!!
- 各位大哥哥 大姐姐 谢谢帮我解决下 新手. .实在看不懂...
- JSP大哥们过来看看~~~解决这个问题,分好多,慢慢给
- 在JBuilder9.0 怎样把tomcat4.1 升级到 tomcat 5.0 ,请各路大侠伸出援助之手
- 请教关于日期计算的问题
- javascript的问题?请过来看看!
- 各位大哥我是新手,为什么我装了一个JBuilder7,里的的例子运行都运行不了
- 前台:Input type="file" 后台获取文件内容用的是spring注解,本地环境上传图片是好的,发布到服务器上图片读取不到,求大神指点!
- hibernate Many to one 保存one的时候将多的一方设置为null 报错
- 判别时间前后
- struts下jsp如何实现下拉框可选列表的层次结构
package loginwithdb;import java.sql.*;public class UserBean {
private Connection conn;
private PreparedStatement pstmt;
private ResultSet rs;
public UserBean() {
conn = DBConn.getConn();
} public boolean validate(String username, String pwd) {
String sqlStr = "select * from userdb where username=? pwd=?";
try {
pstmt = conn.prepareStatement(sqlStr);
pstmt.setString(1, username);
pstmt.setString(2, pwd);
rs = pstmt.executeQuery();
if (rs.next()) {
return true;
}
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ex1) {
}
}
}
return false;
}
}第二段代码:
package loginwithdb;import java.sql.*;public class DBConn {
public static Connection getConn() {
Connection conn = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.sqlserverdriver");
String url =
"jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=northwind";
conn = DriverManager.getConnection(url, "sa", "");
} catch (SQLException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return conn;
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
response.setCharacterEncoding("GBK");
request.setCharacterEncoding("GBK");
HttpSession session = request.getSession();
String username = request.getParameter("username");
String pwd = request.getParameter("pwd");
UserBean userBean = new UserBean();
if(userBean.validate(username,pwd)){
session.setAttribute("username",username);
response.sendRedirect("welcome.jsp");
}else{
response.sendRedirect("login.jsp");
}
}
可能是没有得到conn=null
2.确定数据库名称,用户名和密码为"northwind","sa",""