Passing an Array to a SQL query using Java's PreparedStatement

后端 未结 1 1004
无人共我
无人共我 2020-12-22 06:12

I\'ve been having a little trouble passing an array into a SQL query using Java\'s prepared statements. I had first tried the sourceforge driver, however I would get the Abs

相关标签:
1条回答
  • 2020-12-22 06:39

    I solved same issue by dynamically generating string with required number of question marks. Here's a snippet:-

    String param = "(";
    for(int i=0;i<suppliers.length;i++){
    param = param+"?,";
    }
    param = param.substring(0,param.length()-1);
    param=param+")";
    
    query = query + param;
    
    PreparedStatement ps = connection.prepareStatement(query);
    
    for(int i=0;i<suppliers.length;i++){
    ps.setString(i+1,suppliers[i]);
    }
    
    0 讨论(0)
提交回复
热议问题