HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception java.lang.NullPointerException
com.wy.tool.JDBConnection.executeQuery(JDBConnection.java:52)
com.wy.dao.ConsumerDao.getConsumerForm(ConsumerDao.java:98)
com.wy.webiter.ConsumerServlet.checkConsumer(ConsumerServlet.java:169)
com.wy.webiter.ConsumerServlet.doGet(ConsumerServlet.java:16)
com.wy.webiter.ConsumerServlet.doPost(ConsumerServlet.java:186)
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.5.20 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.5.20
请问如何解决?
com.wy.tool.JDBConnection.executeQuery(JDBConnection.java:52)
com.wy.dao.ConsumerDao.getConsumerForm(ConsumerDao.java:98)
com.wy.webiter.ConsumerServlet.checkConsumer(ConsumerServlet.java:169)
com.wy.webiter.ConsumerServlet.doGet(ConsumerServlet.java:16)
com.wy.webiter.ConsumerServlet.doPost(ConsumerServlet.java:186)
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.5.20 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.5.20
请问如何解决?
解决方案 »
- fusioncharts3.2.1加载问题
- commom-fileupload的一个小问题
- 有谁用过selectM(按ctrl可同时选中多个选项)
- logic标签一导入就报错,为什么啊?
- 菜鸟求助
- 怎么使用连接池,要注意什么?请高手maxActive="99999"
- 谁有jsp-api.jar的源代码
- 关于jsp网站开发的问题?
- javax.mail.internet.ParseException: Unbalanced quoted string
- 显示格式的问题
- 简单+高分! web service 中的stub /skeleton有什么作用
- 关于 html:select,html:optionsCollection的问题,请高手帮忙
以下为代码,各位帮忙看下,//JDBConnection.java 代码:package com.wy.tool;import java.sql.*;public class JDBConnection {
private final String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_BlodMay";
private final String userName = "sa";
private final String password = "";
private Connection con = null;
//通过构造方法加载数据库驱动
static {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
} catch (Exception ex) {
System.out.println("数据库加载失败");
}
}
//创建数据库连接
public boolean creatConnection() {
try {
con = DriverManager.getConnection(url, userName, password);
con.setAutoCommit(true); } catch (SQLException e) {
System.out.println(e.getMessage());
System.out.println("creatConnectionError!");
}
return true;
}
//对数据库的增加、修改和删除的操作
public boolean executeUpdate(String sql) {
if (con == null) {
creatConnection();
}
try {
Statement stmt = con.createStatement();
int iCount = stmt.executeUpdate(sql);
System.out.println("操作成功,所影响的记录数为" + String.valueOf(iCount));
return true;
} catch (SQLException e) {
System.out.println(e.getMessage());
return false;
}
}
//对数据库的查询操作
public ResultSet executeQuery(String sql) {
ResultSet rs;
try {
if (con == null) {
creatConnection();
}
Statement stmt = con.createStatement();
try {
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
System.out.println(e.getMessage());
return null;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
System.out.println("executeQueryError!");
return null;
}
return rs;
}
}//ConsumerDao.java 代码:package com.wy.dao;import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;import com.wy.form.ConsumerForm;
import com.wy.tool.JDBConnection;public class ConsumerDao {
private JDBConnection connection = null; private ConsumerForm consumerForm = null; public ConsumerDao() {
connection = new JDBConnection();
} // 以数据库编号为条件,修改用户信息
public boolean front_updateConsumerForm(ConsumerForm form) {
boolean flag = false;
String sql = "update tb_consumer set account='" + form.getAccount()
+ "',password='" + form.getPassword() + "',name='"
+ form.getName() + "',sex='" + form.getSex() + "',QQNumber='"
+ form.getQQNumber() + "',mainPage='" + form.getMainPage()
+ "',interest='" + form.getInterest() + "',eMail='"
+ form.getEMail() + "' where id='" + form.getId() + "'";
if (connection.executeUpdate(sql)) {
flag = true;
}
return flag;
} // 更新用户操作 public boolean updateConsumerForm(ConsumerForm form) {
boolean flag = false;
String sql = "update tb_consumer set account='" + form.getAccount()
+ "',password='" + form.getPassword() + "',name='"
+ form.getName() + "',sex='" + form.getSex() + "',QQNumber='"
+ form.getQQNumber() + "',mainPage='" + form.getMainPage()
+ "',interest='" + form.getInterest() + "',eMail='"
+ form.getEMail() + "' where manageLevel='"
+ form.getManageLevel() + "'";
if (connection.executeUpdate(sql)) {
flag = true;
}
return flag;
} // 删除用户信息
public boolean deleteConsumerForm(String account) {
boolean flag = false;
String sql = "delete from tb_consumer where account='" + account + "'";
if (connection.executeUpdate(sql)) {
flag = true;
}
return flag;
} // 添加用户信息
public boolean addConsumerForm(ConsumerForm form) {
boolean flag = false;
String sql = "insert into tb_consumer values ('" + form.getAccount()
+ "','" + form.getPassword() + "','" + form.getName() + "','"
+ form.getSex() + "','" + form.getQQNumber() + "','"
+ form.getMainPage() + "','" + form.getInterest() + "','"
+ form.getEMail() + "','" + form.getManageLevel() + "')"; if (connection.executeUpdate(sql)) {
flag = true;
}
return flag;
}
public String getConsumerForm(Integer id) {
String sql = "select * from tb_consumer where id='" + id
+ "'";
String name="";
try {
ResultSet rs = connection.executeQuery(sql);
while (rs.next()) {
name=rs.getString("name");
}
} catch (SQLException e) {
e.printStackTrace();
}
return name;
}
// 以用户名为查询条件,查询一组数据
public ConsumerForm getConsumerForm(String account) {
String sql = "select * from tb_consumer where account='" + account
+ "'";
try {
ResultSet rs = connection.executeQuery(sql);
while (rs.next()) {
consumerForm = new ConsumerForm();
consumerForm.setId(Integer.valueOf(rs.getString(1)));
consumerForm.setAccount(rs.getString(2));
consumerForm.setPassword(rs.getString(3));
consumerForm.setName(rs.getString(4));
consumerForm.setSex(rs.getString(5));
consumerForm.setQQNumber(rs.getString(6));
consumerForm.setMainPage(rs.getString(7));
consumerForm.setInterest(rs.getString(8));
consumerForm.setEMail(rs.getString(9));
consumerForm.setManageLevel(rs.getString(10));
}
} catch (SQLException e) {
e.printStackTrace();
}
return consumerForm;
} // 根据用户账号查询所有的数据
public List getConsumerList(String manageLevel) {
List list = new ArrayList();
String sql = "select * from tb_consumer where manageLevel='"
+ manageLevel + "'";
try {
ResultSet rs = connection.executeQuery(sql);
while (rs.next()) {
consumerForm = new ConsumerForm();
consumerForm.setId(Integer.valueOf(rs.getString(1)));
consumerForm.setAccount(rs.getString(2));
consumerForm.setPassword(rs.getString(3));
consumerForm.setName(rs.getString(4));
consumerForm.setSex(rs.getString(5));
consumerForm.setQQNumber(rs.getString(6));
consumerForm.setMainPage(rs.getString(7));
consumerForm.setInterest(rs.getString(8));
consumerForm.setEMail(rs.getString(9));
consumerForm.setManageLevel(rs.getString(10));
list.add(consumerForm);
}
} catch (SQLException e) {
e.printStackTrace();
} return list;
}}各位帮忙看下,谢了
看下你控制台输出的是什么
并且指出52行在哪里
怀疑创建链接失败
con = DriverManager.getConnection(url, userName, password);
public ResultSet executeQuery(String sql) {
ResultSet rs;
try {
if (con == null) {
creatConnection();
}
Statement stmt = con.createStatement(); //52行位置
try {
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
System.out.println(e.getMessage());
return null;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
System.out.println("executeQueryError!");
return null;
}
return rs;
}
if(rs!=NULL),试一下。