【问题标题】:my SQL statement is wrong? [closed]我的 SQL 语句错了? [关闭]
【发布时间】:2015-11-04 09:54:19
【问题描述】:
    theStatement = theConnection.prepareStatement("INSERT INTO `delldb`.`campaigns`"
         + " (`CAMPAIGN_NAME`, `CAMPAIGN_CREATOR`, `CAMPAIGN_TOTALCOST`, `CAMPAIGN_DESC`, `CAMPAIGN_STARTTIME`," // 5
         + " `CAMPAIGN_ENDTIME`, `CAMPAIGN_DATE`, `CAMPAIGN_VENUEADDRESS`, `CAMPAIGN_EST_ATTENDEES`, " // 4 (9)
         + "`CAMPAIGN_MDF_REQUEST`, `CAMPAIGN_REIMBURSEMENT`, " // 2 (11)
         + "`CAMPAIGN_PARTICIPANTS`, `CAMPAIGN_EST_OPPORTUNITIES`, `CAMPAIGN_TECH_PARTNERS`, `CAMPAIGN_EST_REVENUE`, " // 4 (15)
         + "`CAMPAIGN_SOFTWARE_COMPONENT`, `CAMPAIGN_PRODUCTS_DISCUSS`, `CAMPAIGN_TARGET_AUDIENCE`, " // 3 (18)
         + " `CAMPAIGN_SUBMISSIONDATE`, `CAMPAIGN_VENUE_NAME`, `CAMPAIGN_PROGRAMTYPE`, `CAMPAIGN_CONTACT_NAME`, " // 4 (22)
         + " `CAMPAIGN_COMPANY_NAME`, `CAMPAIGN_COMPANY_ADRESS`, `CAMPAIGN_CONTACT_MAIL`, `CAMPAIGN_CONTACT_PHONE`, `CAMPAIGN_SUBMISSION_DATE` " // 5 (27)

         + " VALUES "

         + " (?, ?, ?, ?, ?, ?, ?, ?,"    // 8
         + " ?, ?, ?, ?, ?, ?, ?, ?, ?, " // 9 (17)
         + "?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "); // 10 (27)                          

         theStatement.setString(1, request.getParameter("name")); 
         theStatement.setString(2, "2");//request.getParameter("CreatorID")); 
         theStatement.setString(3, request.getParameter("projectedcost"));  
         theStatement.setString(4, "my description");//request.getParameter("desc"));  
         theStatement.setString(5, request.getParameter("starttime"));
         theStatement.setString(6, request.getParameter("endtime")); 
         theStatement.setString(7, request.getParameter("programdate")); 
         theStatement.setString(8, request.getParameter("venueaddress"));  
         theStatement.setString(9, request.getParameter("estatt"));
         theStatement.setString(10, request.getParameter("mdfrequest")); 
         theStatement.setString(11, request.getParameter("reimbursementmethod")); 
         theStatement.setString(12, request.getParameter("partners")); 
         theStatement.setString(13, request.getParameter("opportunities")); 
         theStatement.setString(14, request.getParameter("partnercontribution"));  
         theStatement.setString(15, request.getParameter("estimatedrevenue")); 
         theStatement.setString(16, request.getParameter("softwarecomponent"));   
         theStatement.setString(17, checkboxproductstodiscuss); 
         theStatement.setString(18, checkboxtypeprogram);    
         theStatement.setString(19, request.getParameter("submissiondate")); 
         theStatement.setString(20, request.getParameter("venuename")); 
         theStatement.setString(21, checkboxtargetaudience);
         theStatement.setString(22, request.getParameter("contactname")); 
         theStatement.setString(23, request.getParameter("company"));  
         theStatement.setString(24, request.getParameter("companyadress"));  
         theStatement.setString(25, request.getParameter("contactemail")); 
         theStatement.setString(26, request.getParameter("contactphone")); 
         theStatement.setString(27,  request.getParameter("submissiondate")); 

我真的找不到这个问题吗?这个 SQL 语句有什么问题?帮助将不胜感激。 (在这种方式之前确实有效)我似乎无法找出故障。

我收到这个错误

javax.servlet.ServletException:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 你有一个 SQL 语法错误;检查或响应您的手册 MySQL 服务器版本,用于在 'VALUES ('a', '2', '123', '我的描述', '12', '13', '2005-11-11', 'ee', '121' at 第 1 行

【问题讨论】:

    标签: mysql sql jdbc


    【解决方案1】:

    在列列表后添加右括号:

    INSERT INTO tab(column_list) VALUES (...);
    

    在你的例子中:

     + " `CAMPAIGN_COMPANY_NAME`, `CAMPAIGN_COMPANY_ADRESS`, `CAMPAIGN_CONTACT_MAIL`, `CAMPAIGN_CONTACT_PHONE`, `CAMPAIGN_SUBMISSION_DATE`) " // 5 (27)
    

    【讨论】:

    猜你喜欢
    • 2012-08-11
    • 1970-01-01
    • 2021-03-03
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 1970-01-01
    • 2011-12-17
    • 1970-01-01
    相关资源
    最近更新 更多