简单的JSP+SERVLET图书管理程序!!数据库好像出了问题麻烦大神们帮忙看看!!!蟹蟹!!

Seconddddd 2016-05-28 05:18:27


我建的数据库名字叫book, 有两张表 books 和users


语句里并没有写user 而且怎么会出现 book.user这种奇怪的报错


下面是用户登录注册对数据库的操作,报错行已加粗:
public class UserDao {
private Connection conn;
//用户注册
public boolean registerUser(User user) throws Exception{
conn = DBCon.getConnection();
String sql = "insert into users (name,password)values(?,?)";
PreparedStatement ps = conn.prepareStatement(sql);

try{
ps.setString(1, user.getName());
ps.setString(2, user.getPwd());
ps.executeUpdate();
conn.commit();
return true;
}catch(SQLException e){
conn.rollback();//数据回滚,有一条数据插入失败所有的都不插入,数据库回滚到操作之前的样子
e.printStackTrace();
}finally{
conn.close();
}
return false;
}

//登录
public boolean login(User user) throws Exception{
conn = DBCon.getConnection();
String sql1 ="select * from users where name='"+user.getName()+"' and password = '"+user.getPwd()+"'";
PreparedStatement ps = conn.prepareStatement(sql1);
ResultSet rs = ps.executeQuery();
if(rs.next()){
System.out.print("----"+rs);
return true;
}
return false;
}


下面是login的servlet,同样有报错行:

public class ServletLogin extends HttpServlet {

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doPost(request,response);
}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

request.setCharacterEncoding("utf-8");
HttpSession session = request.getSession();
String username = request.getParameter("username");
String pwd = request.getParameter("pwd");
String forward = "";
User user = new User();
user.setName(username);
user.setPwd(pwd);
if(username.equals("")&&username!=null&&pwd.equals("")&&pwd!=null){
forward="error.jsp";
}else
if(username.equals("admin")&&username!=null&&pwd.equals("admin")&&pwd!=null){
BookDao bookdao = new BookDao();
List list = bookdao.findBooks();
request.setAttribute("booklist", list);
forward = "menu.jsp";
}else{
UserDao userdao = new UserDao();
try {
userdao.login(user);
session.setAttribute("username", username);
BookDao bookdao = new BookDao();
List list = bookdao.findBooks();
request.setAttribute("booklist", list);
forward = "menu.jsp";
forward="userhome.jsp";
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
RequestDispatcher rd = request.getRequestDispatcher(forward);
rd.forward(request, response);
}

}

麻烦大家看看!!!
...全文
204 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
NONE_LANG 2016-05-30
  • 打赏
  • 举报
回复
nikyotensai 2016-05-30
  • 打赏
  • 举报
回复
数据库名的问题
幺客 2016-05-30
  • 打赏
  • 举报
回复
楼上正解,我就没看见book表,当然会报table ‘book.user’不存在了,你建了一个数据库叫book,可是你下面没有book表啊!
henry_韩 2016-05-29
  • 打赏
  • 举报
回复
报出的错误就是user表不存在 你看下你是不是能错了?
Simplxs 2016-05-29
  • 打赏
  • 举报
回复
数据库表名最好与实体bean名称一致,把实体User改为Users再试试、
Nnick_s 2016-05-29
  • 打赏
  • 举报
回复
错误信息长度不够,看不到是从代码哪里报错了,把报错信息完整贴出来,或是你自己代码出错地方贴出来。还有你这里userdao.login(user);调用不处理返回值的吗?
anakin_feng 2016-05-28
  • 打赏
  • 举报
回复
不是说了数据库中表user不存在吗,你的表是users

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧