打印

[Java] 濒临崩溃-恳请大虾出手相助!

濒临崩溃-恳请大虾出手相助!

想做一个迷你的管理软件,没想到出了N个错,到了这个怎么也搞不定了,还望大虾指点!

这个错是在信息录入页,按完提交出的,可是我怎么也不明白,Sql语句错在哪了??

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 'describe,money,realMoney,moreMoney,addContent,mobile1,mobile2,phone,weight,high,' at line 1
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2822)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1536)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1626)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:3031)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:943)
        at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:768)
        at com.flower.www.persistence.CustomerInfoDao.inserCustomerInfo(CustomerInfoDao.java:94)
        at com.flower.www.service.CustomerInfoFacadeImpl.insertCustomerInfo(CustomerInfoFacadeImpl.java:18)
        at com.flower.www.webtier.CustomerInfoController.insertCustomerInfo(CustomerInfoController.java:97)
        at com.flower.www.webtier.CustomerInfoController.doGet(CustomerInfoController.java:183)
        at com.flower.www.webtier.CustomerInfoController.doPost(CustomerInfoController.java:202)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Unknown Source)
Error Trace in inserCustomerInfo() : 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 'describe,money,realMoney,moreMoney,addContent,mobile1,mobile2,phone,weight,high,' at line 1

其它部分代码如下:

[ 本帖最后由 10bossboss 于 2008-6-14 08:13 编辑 ]

TOP

package com.flower.www.persistence;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

import org.omg.CORBA.Request;

import com.flower.www.domian.CustomerInfo;

public class CustomerInfoDao {
        private Connection dataConnection;
        final static String selectStr = "select * from customerinfo";
        final static String insertStr = "insert into customerinfo(customerName,age,sex,date,describe,money,realMoney,moreMoney,addContent,mobile1,mobile2,phone,weight,high,birthday,qq,email,range,caiKuo,caiPen,shuiBan,xiangKuang,xiaoJian,ckFlag,cpFlag,sbFlag,xkFlag,xjFlag,good1,good2,good3,good4,good5,g1,g2,g3,g4,g5)" +
                                                                    "value(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        final static String updateStr = "update customerinfo set ";
        final static String deleteStr = "delete customerinfo where ";
        final static String findStr = "select * from customerinfo where customerName = ?";
        final static String findStr2Test = "select * from customerinfo where age = ?";
       
        public CustomerInfoDao() {
                DataBaseConnect dataBaseConnect = null;
                try {
                        dataBaseConnect = new DataBaseConnect();
                } catch (ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        System.out.println("Error Trace in CustomerInfo() constructor1 : " + e.getMessage());
                } catch (IllegalAccessException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        System.out.println("Error Trace in CustomerInfo() constructor : " + e.getMessage());
                } catch (InstantiationException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        System.out.println("Error Trace in CustomerInfo() constructor: " + e.getMessage());
                } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        System.out.println("Error Trace in CustomerInfo() constructor: " + e.getMessage());
                }
                dataConnection = dataBaseConnect.dataConnection;
        }
       
        public int inserCustomerInfo(CustomerInfo customerInfo) throws Exception {
                try {
                        PreparedStatement statement = dataConnection.prepareStatement(insertStr);
                        String date = customerInfo.getDate();
                        String birthday = customerInfo.getBirthday();
                        System.out.println(date);
                        System.out.println(birthday);
                       
                        statement.setString(1, customerInfo.getCustomerName());
                        statement.setInt(2, customerInfo.getAge());
                        statement.setString(3, customerInfo.getSex());
                        statement.setDate(4, customerInfo.string2Date(date));
                       
                        statement.setString(5, customerInfo.getDescribe());
                        statement.setInt(6, customerInfo.getMoney());
                        statement.setInt(7, customerInfo.getRealMoney());
                        statement.setInt(8, customerInfo.getMoreMoney());
                        statement.setString(9, customerInfo.getAddContent());
                        statement.setString(10, customerInfo.getMobile1());
                        statement.setString(11, customerInfo.getMobile2());
                        statement.setString(12, customerInfo.getPhone());
                        statement.setInt(13, customerInfo.getWeight());
                        statement.setInt(14, customerInfo.getHigh());
                        statement.setDate(15, customerInfo.string2Date(birthday));
                       
                        statement.setString(16, customerInfo.getQq());
                        statement.setString(17, customerInfo.getEmail());
                        statement.setInt(18, customerInfo.getRange());
                        statement.setString(19, customerInfo.getCaiKuo());
                        statement.setString(20, customerInfo.getCaiPen());
                        statement.setString(21, customerInfo.getShuiBan());
                        statement.setString(22, customerInfo.getXiangKuang());
                        statement.setString(23, customerInfo.getXiaoJian());
                        statement.setInt(24, customerInfo.getCkFlag());
                        statement.setInt(25, customerInfo.getCpFlag());
                        statement.setInt(26, customerInfo.getSbFlag());
                        statement.setInt(27, customerInfo.getXkFlag());
                        statement.setInt(28, customerInfo.getXjFlag());
                        statement.setString(29, customerInfo.getGood1());
                        statement.setString(30, customerInfo.getGood2());
                        statement.setString(31, customerInfo.getGood3());
                        statement.setString(32, customerInfo.getGood4());
                        statement.setString(33, customerInfo.getGood5());
                        statement.setInt(34, customerInfo.getG1());
                        statement.setInt(35, customerInfo.getG2());
                        statement.setInt(36, customerInfo.getG3());
                        statement.setInt(37, customerInfo.getG4());
                        statement.setInt(38, customerInfo.getG5());
                       
                        statement.execute();
                       
                } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        System.out.println("Error Trace in inserCustomerInfo() : " + e.getMessage());

                }
                return 1;
               
        }
               
               
        public CustomerInfo findCustomerInfo(CustomerInfo customerInfo) {
                CustomerInfo acustomerInfo = new CustomerInfo();
                System.out.println("CustomerInfoDao"+customerInfo.getCustomerName());
                System.out.println("CustomerInfoDao"+customerInfo.getAge());
                try {
                        PreparedStatement statement = dataConnection.prepareStatement(findStr2Test);
                //        statement.setString(1, customerInfo.getCustomerName());
                        statement.setInt(1, customerInfo.getAge());
                        ResultSet result = statement.executeQuery();
                        while(result.next()) {
                                acustomerInfo.setId(new Integer(result.getInt("id")));
                                acustomerInfo.setCustomerName(result.getString("customerName"));
                                acustomerInfo.setAge(result.getInt("age"));
                                acustomerInfo.setSex(result.getString("sex"));
                                acustomerInfo.setDate(result.getString("date"));
                                acustomerInfo.setDescribe(result.getString("describe"));
                                acustomerInfo.setMoney(result.getInt("money"));
                                acustomerInfo.setRealMoney(result.getInt("realMoney"));
                                acustomerInfo.setMoreMoney(result.getInt("moreMoney"));
                                acustomerInfo.setAddContent(result.getString("addContent"));
                                acustomerInfo.setMobile1(result.getString("mobile1"));
                                acustomerInfo.setMobile2(result.getString("Mobile2"));
                                acustomerInfo.setPhone(result.getString("phone"));
                                acustomerInfo.setWeight(result.getInt("weight"));
                                acustomerInfo.setHigh(result.getInt("high"));
                                acustomerInfo.setBirthday(result.getString("birthday"));
                                acustomerInfo.setQq(result.getString("qq"));
                                acustomerInfo.setEmail(result.getString("email"));
                                acustomerInfo.setRange(result.getInt("range"));
                                acustomerInfo.setCaiKuo(result.getString("caiKuo"));
                                acustomerInfo.setCaiPen(result.getString("caiPen"));
                                acustomerInfo.setShuiBan(result.getString("shuiBan"));
                                acustomerInfo.setXiangKuang(result.getString("xiangKuang"));
                                acustomerInfo.setXiaoJian(result.getString("xiaoJian"));
                                acustomerInfo.setCkFlag(result.getInt("ckFlag"));
                                acustomerInfo.setCpFlag(result.getInt("cpFlag"));
                                acustomerInfo.setSbFlag(result.getInt("sbFlag"));
                                acustomerInfo.setXkFlag(result.getInt("xkFlag"));
                                acustomerInfo.setXjFlag(result.getInt("xjFlag"));
                                acustomerInfo.setGood1(result.getString("good1"));
                                acustomerInfo.setGood2(result.getString("good2"));
                                acustomerInfo.setGood3(result.getString("good3"));
                                acustomerInfo.setGood4(result.getString("good4"));
                                acustomerInfo.setGood5(result.getString("good5"));
                                acustomerInfo.setG1(result.getInt("g1"));
                                acustomerInfo.setG2(result.getInt("g2"));
                                acustomerInfo.setG3(result.getInt("g3"));
                                acustomerInfo.setG4(result.getInt("g4"));
                                acustomerInfo.setG5(result.getInt("g5"));
                        }
                } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        System.out.println("Error Trace in findCustomerInfo() : " + e.getMessage());
                }
                return acustomerInfo;
       
        }

}

TOP

"insert into customerinfo(customerName,age,sex,date,describe,money,realMoney,moreMoney,addContent,mobile1,mobile2,phone,weight,high,birthday,qq,email,range,caiKuo,caiPen,shuiBan,xiangKuang,xiaoJian,ckFlag,cpFlag,sbFlag,xkFlag,xjFlag,good1,good2,good3,good4,good5,g1,g2,g3,g4,g5)" +
                                                                    "value(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
怎么看都不对啊

TOP

values

TOP

引用:
原帖由 xiaoxiaoqian 于 2008-6-14 17:07 发表
values

TOP

把生成的sql打印出来,然后在mysql上运行一下,看一下那里语法错误了
路要一步一步走,抛除浮躁的心情,静下心来,提高自己!

TOP

value前面加个空格

TOP

应该是VALUES的问题

TOP

感谢各位的帮忙,问题已经解决了!

TOP

ps  字段名尽量不要用关键字 e.g. describe
[php] 使君欲醉离亭酒 酒醒离愁转有 紫禁多时虚右 苕霄留难久 一声歌掩双罗袖 日落乱山春后 犹有东城烟柳 青荫长依旧 [/php]

TOP


感谢一直以来您对我们的支持!
当前时区 GMT+8, 现在时间是 2008-12-3 08:47 京ICP证060528 号

Designed By 17DST