您的位置:程序门 -> java -> j2ee / ejb / jms



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


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


为什么会出现这样的错误:unknown column 'aa' in 'field list'[已结贴,结贴人:lzyboy]
发表于: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> &nbsp; </td>
        <td> &nbsp; </td>
        <td   width= "238 "> &quot;*&quot;带有这个符号的为必添项 </td>
        <td   width= "48 "> &nbsp; </td>
        <td   width= "388 "> &nbsp; </td>
    </tr>
    <tr>
        <td   width= "68 "> &nbsp; </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> &nbsp; </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> &nbsp; </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> &nbsp; </td>
        <td> *内容: </td>
        <td   colspan= "3 "> <textarea   name= "newscontent "   cols= "60 "   rows= "15 "   id= "newscontent "> </textarea> </td>
        </tr>
    <tr>
        <td> &nbsp; </td>
        <td> &nbsp; </td>
        <td   colspan= "3 "> <input   name= " "   type= "submit "   /> &nbsp; <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;
}
}

}
发表于:2007-04-13 11:53:031楼 得分:0
人呢??,快来帮我看看啊!!迷糊~~~
发表于:2007-04-13 11:54:342楼 得分:100
是sql拼得不对吧
发表于:2007-04-13 11:57:293楼 得分:0
sql写的对啊   ,     我向数据库里写数字是可以的   就是写不了   汉字和英文!!
发表于:2007-04-13 12:07:574楼 得分:0
顶起,等待高人解答!!
发表于:2007-04-13 12:54:165楼 得分:0
ever_li(ipaizi)     谢谢,是我的sql写的不对!!


快速检索

最新资讯
热门点击