Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误:在eclipse(java)中,INSERT的目标列多于表达式_Java_Postgresql_Sql Insert - Fatal编程技术网

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

错误:在eclipse(java)中,INSERT的目标列多于表达式,java,postgresql,sql-insert,Java,Postgresql,Sql Insert,我需要在数据库中添加记录。但是当我这么做的时候。。我有一个问题:( 我不知道我做错了什么:( 帮助 请格式化您的代码 你可能想要这样的东西: String insertSQL = "INSERT INTO MyTable (StrCol1, StrCol2) VALUES (?, ?)"; PreparedStatement preparedStatement = dbConnection.prepareStatement(insertSQL); preparedStatement.setStr

我需要在数据库中添加记录。但是当我这么做的时候。。我有一个问题:( 我不知道我做错了什么:( 帮助


请格式化您的代码

你可能想要这样的东西:

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();

我的朋友,你已经错过了很久了

,工作时间,主题,描述 价值观 “测试”

请使用下面的代码并尝试运行该方法/类

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)  ";

}
我相信您知道如何建立数据库连接和插入记录。 如果没有回复我,我将与大家分享这方面的代码片段。
希望这能解决您的问题。

i knooww!i missing“,”:不要像这样连接SQL语句。如果变量值中有特殊字符,并且您非常容易受到SQL注入攻击,则会出现语法错误。请使用准备好的语句。
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)  ";

}