2015-11-04 56 views
1
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語句有什麼問題?幫助將很樂意欣賞。 (在這種方式之前它確實工作),我似乎無法找出故障。我的SQL語句是錯誤的?

我得到這個錯誤

javax.servlet.ServletException:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您在您的SQL語法錯誤 ; ('''', '2','123','我的描述','12','13','2005-xxxxx')附近使用正確的語法來查看對應於您的 MySQL服務器版本的手冊。 11-11' , 'EE', '在 線121' 1

回答

3

後列的列表中添加閉架:

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

在您的例子:

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

非常感謝你,現在已經忽略了過去一小時:-)乾杯和感謝:-) –

+0

@SebastianRyberg不客氣。不要忘記打勾回答http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235 :) – lad2025