为什么会出现这样的错误:Unknown column 'aa' in 'field list'

SilenceSoul 2007-04-13 11:41:50
News.jsp 页:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" type="text/css" href="style.css"/>
<title>添加新闻</title>
</head>
<body>
<form action="addNews.jsp" method="post">
<table width="800" border="0">
<tr>
<td> </td>
<td> </td>
<td width="238">"*"带有这个符号的为必添项</td>
<td width="48"> </td>
<td width="388"> </td>
</tr>
<tr>
<td width="68"> </td>
<td width="36">*标题:</td>
<td><input name="newsTitle" type="text" id="newsTitle" size="30" /></td>
<td>类 型:</td>
<td width="388">
<select name="newsLx" id="newsLx">
<option selected="selected" value="0">选择新闻类型</option>
<option value="1">热点新闻</option>
<option value="2">行业新闻</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td>*作者:</td>
<td width="238"><input name="newsAuthor" type="text" id="newsAuthor" /></td>
<td width="48"> 时 间:</td>
<td width="388"><input name="newsTime" type="text" id="time" onClick="getDateString(this,oCalendarChs)" value="点击输入时间" readonly></td>
</tr>
<tr>
<td> </td>
<td>*来源:</td>
<td width="238"><input name="newsCfrom" type="text" id="newsCfrom" /></td>
<td width="48">*关键字:</td>
<td width="388"><input name="newsKeyword" type="text" id="newsKeyword" /></td>
</tr>
<tr>
<td> </td>
<td>*内容:</td>
<td colspan="3"><textarea name="newsContent" cols="60" rows="15" id="newsContent"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"><input name="" type="submit" /> <input name="" type="reset" /></td>
</tr>
</table>
</form>
</body>
</html>


addNews.jsp 页:

<%@ page contentType="text/html; charset=gb2312" language="java" errorPage=""%>
<jsp:useBean id="conn" scope="page" class="news.conn" />
<html>
<%
String title = request.getParameter("newsTitle");
String lx = request.getParameter("newsLx");
String author = request.getParameter("newsAuthor");
String newstime = request.getParameter("newsTime");
String Cfrom = request.getParameter("newsCfrom");
String keyword = request.getParameter("newsKeyword");
String content = request.getParameter("newsContent");
String sql="insert into news(title,type,author,time,Cfrom,keyword,content) values("+title+",'"+lx+"','"+author+"','"+newstime+"','"+Cfrom+"','"+keyword+"','"+content+"')";
int ret=0;
ret=conn.executeUpdate(sql);
if (ret!=0){
out.println("<script language='javascript'>alert('成功!');window.location.href='index.html';</script>");
}else{
out.println("<script language='javascript'>alert('失败!');window.location.href='index.html';</script>");
}
%>
<head>
<title>添加新闻</title>
</head>
<body>
</body>
</html>


conn.java

package news;
import java.sql.*;

public class conn {
String sDBDriver ="com.mysql.jdbc.Driver";
String sConnStr = "jdbc:mysql://localhost:3306/news";
Connection connect = null;
ResultSet rs = null;

public conn(){
try{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e){
System.err.print(e.getMessage());
}
}

public ResultSet executeQuery(String sql){
try{
connect = DriverManager.getConnection(sConnStr,"root","lzyboy");
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex){
System.err.print( ex.getMessage());
}
return rs;
}

public int executeinsert(String sql){
int result = 0;
try{
connect = DriverManager.getConnection(sConnStr,"root","lzyboy");
Statement stmt = connect.createStatement();
result = stmt.executeUpdate(sql);
}
catch(SQLException ex){
System.err.print(ex.getMessage());
}
return result;
}

public int executeUpdate(String sql){
int result = 0;
try{
connect = DriverManager.getConnection(sConnStr, "root", "lzyboy");
Statement stmt = connect.createStatement();
result = stmt.executeUpdate(sql);
}
catch(SQLException ex){
System.err.print(ex.getMessage());
}
return result;
}

public void close(){
if(connect!=null){
try{
connect.close();
connect = null;
}
catch(SQLException ex){
System.err.print(ex.getMessage());
}
}
}

public static String toChinese(String strvalue){
try{
if(strvalue == null){
return null;
}
else{
strvalue = new String(strvalue.getBytes("ISO8859_1"),"GBK");
return strvalue;
}
}
catch(Exception ex){
return null;
}
}

}
...全文
10809 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxh_line 2012-02-16
  • 打赏
  • 举报
回复
检查hbm文件,属性的name对应的column是否正确,column是数据库中的字段
雨木林风 2011-12-01
  • 打赏
  • 举报
回复
sql语句中字段类型不匹配!
零度空间0520 2011-09-26
  • 打赏
  • 举报
回复
学习来的。。。
SilenceSoul 2007-04-13
  • 打赏
  • 举报
回复
ever_li(ipaizi) 谢谢,是我的SQL写的不对!!
SilenceSoul 2007-04-13
  • 打赏
  • 举报
回复
顶起,等待高人解答!!
SilenceSoul 2007-04-13
  • 打赏
  • 举报
回复
SQL写的对啊 , 我向数据库里写数字是可以的 就是写不了 汉字和英文!!
ever_li 2007-04-13
  • 打赏
  • 举报
回复
是sql拼得不对吧
SilenceSoul 2007-04-13
  • 打赏
  • 举报
回复
人呢??,快来帮我看看啊!!迷糊~~~

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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