mysql - 我的SQL语句错了吗?

标签 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: You have an error in your SQL syntax; check the manual that orresponds to your MySQL server version for the right syntax to use near 'VALUES ('a', '2', '123', 'my description', '12', '13', '2005-11-11', 'ee', '121' at line 1

最佳答案

在列列表后添加右括号:

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

在你的例子中:

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

关于mysql - 我的SQL语句错了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33518670/

相关文章:

mysql - MySQL相对于其他数据库的缺点

mysql - 我无法弄清楚这个查询

java - 使用 JDBC 选择 "for update"?

hibernate - 在 hibernate 应用程序中使用 P6Spy 拦截对数据库的 JDBC 语句

mysql 在 Oracle Linux 上无法启动

mysql - 删除带有外键的行( Entity Framework )

php - 在 PHP 中运行 MySQL *.sql 文件

MySQL #1215 问题

SQL 在没有子查询的情况下获取最新结果

java - 部署到 Web 服务器时 MySQL JDBC 连接失败