错误:INSERT的目标列多于eclipse中的表达式(java)

时间:2017-05-05 08:55:57

标签: eclipse postgresql insert sql-insert insert-into

我需要在数据库上添加记录。但当我做这个代码..我有一个问题:( 我不知道我做错了什么:( 帮助

public void addTicket(String customersID,String agentID,String campaigns_ID){         String insertTicket =“INSERT INTO workforce.tickets(customers_id,”+“records_id,”+“assigned_agents_id,”+“work_time,”+“subject,”                 +“description”,+“created_at”,“”created_by“,”“标识符”+“campaigns_id”,“+ new_messages”+“last_states_id”“                                                                                 +“VALUES(”+ ConfigDB.customer_id_selenium +“,4983544,NULL,0,'Test','''',now(),”+ ConfigDB.agents_selenium_id                 +“1420610569,”+ ConfigDB.campaign_ticket +“,0,-1)”;

2 个答案:

答案 0 :(得分:0)

请格式化您的代码....

你可能想要这样的东西:

String insertSQL = "INSERT INTO MyTable (StrCol1, StrCol2) VALUES (?, ?)";
PreparedStatement preparedStatement = dbConnection.prepareStatement(insertSQL);
preparedStatement.setString(1, "Val 1");
preparedStatement.setString(2, "Val 2");
preparedStatement.executeUpdate();

答案 1 :(得分:0)

我的朋友你错过了','

的逗号
  

,work_time,主题,描述     值   ,'测试','',''

请使用以下代码并尝试运行方法/类

public void addTicket (String customersID, String agentID, String campaigns_ID) 
{ 
    String insertTicket = " INSERT INTO  "
            +"  workforce.tickets  "
            +"  (customers_id, records_id,assigned_agents_id  "
            +"  ,work_time,subject,description  "
            +"  ,created_at,created_by,identifier,campaigns_id,new_messages, last_states_id)  "
            +"  VALUES   "
            +"  ( "+ConfigDB.customer_id_selenium +" , 4983544 ,NULL,0  "
            +"  ,'Test','', ''  "
            +"  ,now()," + ConfigDB.agents_selenium_id + ", 1420610569, " +ConfigDB.campaign_ticket + ",0, -1)  ";

}

我相信您知道如何建立数据库连接并插入记录。 如果没有回复我,我会分享代码片段。 希望这可以解决您的问题。