我的SQL语句错了?

时间:2015-11-04 09:54:19

标签: mysql sql jdbc

    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行

1 个答案:

答案 0 :(得分:3)

在列列表后添加结束括号:

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

在你的例子中:

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