首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException

2014-01-26 
------解决方法-------------------------------------------------------- 数据库Mysql +--------------+-

------解决方法--------------------------------------------------------

数据库Mysql

+--------------+-------------+------+-----+---------+-------+
| Field  | Type  | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| id  | int(11)  | NO  | PRI |  |  |
| UserName  | varchar(10) | YES  |  | NULL  |  |
| UserPassword | varchar(10) | YES  |  | NULL  |  |
+--------------+-------------+------+-----+---------+-------+

java代码:

User.java(部分):public class User implements Serializable {
private int id;

private String username;

private String password;


UserAccess.java(部分): public void delete(String id) {
String sql = "delete form userinfo where id= "+ id;
Basedao dao = new Basedao();
dao.doInsert(sql);
}

UserMgr.java(部分):public void delete(String id)
{
UserAccess ua = new UserAccess();
ua.delete(id);
}

UserServlet.java(部分):public class UserServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
req.setCharacterEncoding("gbk");
String type = req.getParameter("type");
res.setCharacterEncoding("gbk");
if (type.equals("login")) {
this.login(req, res);
} else if (type.equals("update")) {
this.update(req, res);
} else if (type.equals("add")) {
this.add(req, res);
} else if (type.equals("delete")) {
this.delete(req, res);
} else if (type.equals("list")) {
this.list(req, res);
} else if (type.equals("view")) {
this.list(req, res);
}

}

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

this.doGet(req, res);
}


public void delete(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
UserMgr mgr = new UserMgr();
String id = req.getParameter("id");
mgr.delete(id);
this.list(req, res);

}

}

jsp页面:
userlist.jsp
<%@page contentType="text/html;charset=gbk"%>
<%@page errorPage="error.jsp"%>
<%@page import="java.util.*,com.zhangxu.system.model.*"%> <style type="text/css">
<!--
body,td,th {
font-family: Courier New, Courier, monospace;
font-size: 14px;
}
body {
background-image: url(img/userlistbg.JPG);
}
-->
</style>

<CENTER> <H1>用户列表 </H1> </CENTER>
<HR size=5  color="#000000">
<CENTER> <a href="UserAdd.jsp">新增用户 </a> </CENTER>

<TABLE border=1 align=center>
<TR align=center>
<TD width="161">用户编号 </TD>
<TD width="175">用户名称 </TD>
<TD width="52">用户密码 </TD>
<TD colspan=3>操作 </TD>
</TR>
<TR>
<%
List list = (List)request.getAttribute("list");
for(int i=0;i <list.size();i++)
{
User user= (User)list.get(i);

%>
<TD> <%=user.getId()%> </TD>
<TD> <%=user.getUsername()%> </TD>
<TD>***** </TD>
<TD width="134"> <a href="UserServlet?type=view&id= <%=user.getId()%>"> <font size="+1" color="#FF0000">查看 </font> </a> </TD>
<TD width="166"> <a href="UserServlet?type=delete&id= <%=user.getId()%>"> <font size="+1" color="#0000FF">删除 </font> </a> </TD>
<TD width="73"> <a href="UserServlet?type=update&id= <%=user.getId()%>"> <font size="+1" color="#0000FF">修改 </font> </a> </TD>
</TR>
<%}%>
</TABLE>

当点删除的时候  ID传过去 但是数据库老报错  :com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where id= 3' at line 1