使用选择查询获取数据库批处理记录

时间:2018-07-19 09:51:44

标签: java sql arrays

    public Map<String,String> getData() {
    ResultSet rs = null;
    Connection conn = null;
    PreparedStatement pstmt = null;
   List<String> pos30data = new ArrayList<String>();
     Map<String, String> NameMap=new HashMap<>();
   try {
       conn = getConnection();
       String query = ("select T9F16_COD_CONVENZ" +
           "    , ID_ESRC" +
           "    , RAC_CM_RAGSOC" +
           "    , RAGIONE_SOCIALE" +
           "    , DESCRIZIONE" +
           "      from ..." +
           "      where  and RAC_CM_RAGSOC=?" );

       pstmt = conn.prepareStatement(query);

我正在尝试使用两个不同的.setstring逐个发送的位置执行此查询  我正在搜索示例,但可以看到更新语句,而不是选择语句 例如:JDBC PreparedStatement示例– mkyong中的批处理更新

           pstmt.setString(1, "AAAAAAAA"); 

           pstmt.setString(1, "BBBBBBBB");

       rs = pstmt.executeQuery();

         while (rs.next()) {

             MerchantNumber = rs.getString("T9F16_COD_CONVENZ");

             Name = rs.getString("RAGIONE_SOCIALE");        
           pos30data.add(MerchantNumber);

             NameMap.put(MerchantNumber, Name);

       }

   } catch (Exception e) {
       System.out.println(e);
   }

   return NameMap;
  }

并返回另一个分类

public String getMerchantNumber() {

    return MerchantNumber;
}

在另一堂课上,我要添加键值

while (outlets.hasNext()) {

        OutletElem oElem = outlets.next();

            for(Map.Entry<String,String> merchantData: 
                          oElem.getData().entrySet()){
                                Outlet mOutlet = new 
                               Outlet(merchantData.getKey()
                                        , cElem.getCountry()
                                        , cElem.getCurrency()
                                        , merchantData.getValue()
                                        , oElem.getAddress());

merchantIds.add(merchantData.getKey());

如果您让我知道如何在每次迭代中发送两个不同的setstring,它将为BBBB发送值,将对您有所帮助     实际结果:       1 == BBBB       2 == BBBB       预期:       1 == AAAA       2 == BBBB

0 个答案:

没有答案