JDBCコードは例外をスローしませんが、データベースを挿入または更新することはありません。ここにコードがあります。 また、データベース接続クラスもそれ以降に指定されています。いくつかのデータをローカルで実行しているときにDBに正常に挿入されています。しかし、100万データのようにそれを実行している間、DB操作がDBに反映されることはありません。いずれの場合も、コードによって例外はスローされません。JDBCコードがデータベースに埋め込まれていません
public static void operateDocument(String result) throws SQLException, ClassNotFoundException {
// TODO Auto-generated method stub
OracleDataSource pds;
pds = DatabaseConnection.getConnection();
final int batchSize = 1000;
int count = 0;
JSONArray json;
json = new JSONArray(result);
Map<String, List<JSONObject>> orderMongo = new HashMap<>();
Map<String, List<JSONObject>> orderItemMongo = new HashMap<>();
// Document doc1=new Document();
String key="";
//Gson gson=new Gson();
//BasicDBObject document = new BasicDBObject();
List<JSONObject> nextlist = null;
List<JSONObject> list=null;
for (int i = 0; i < json.length(); i++) {
JSONObject obj = json.getJSONObject(i);
if(obj.getString("table").equals("TEST.S_ORDER")){
list = orderMongo.getOrDefault(obj.getJSONObject("after").getString("ROW_ID"),new ArrayList<>());
list.add(obj);
orderMongo.put(obj.getJSONObject("after").getString("ROW_ID"),list);
}
else if(obj.getString("table").equals("TEST.S_ORDER_ITEM")){
nextlist = orderItemMongo.getOrDefault(obj.getJSONObject("after").getString("ROW_ID"),new ArrayList<>());
nextlist.add(obj);
// System.out.println(obj);
// System.out.println(nextlist);
key=obj.getJSONObject("after").getString("ROW_ID");
orderItemMongo.put(key, nextlist);
}
}
Connection con=pds.getConnection("spring_kafka", "Aug2017");
con.setAutoCommit(true);
for (Entry<String, List<JSONObject>> entry : orderMongo.entrySet()) {
List<JSONObject> listnext = entry.getValue();
for(JSONObject obj:listnext){
String op_type=obj.optString("op_type");
switch(op_type){
case "I":
pst=con.prepareStatement(insertQuery);
pst.setString(1,obj.getJSONObject("after").optString("STATUS_CD"));
pst.setString(2, obj.getJSONObject("after").optString("ROW_ID"));
pst.setString(3, obj.getJSONObject("after").optString("INTEGRATION_ID"));
pst.setString(4, obj.getJSONObject("after").optString("X_CUST_REF"));
pst.setString(5, obj.getJSONObject("after").optString("REQ_SHIP_DT"));
pst.setString(6, obj.getJSONObject("after").optString("QUOTE_ID"));
pst.setString(7, obj.getJSONObject("after").optString("ACCNT_ID"));
pst.setString(8, obj.getJSONObject("after").optString("ACTIVE_FLG"));
pst.setString(9, obj.getJSONObject("after").optString("PROCESS_TIMESTAMP"));
pst.setString(10, obj.getJSONObject("after").optString("CONTACT_ID"));
pst.setString(11, obj.getJSONObject("after").optString("BU_ID"));
pst.setString(12, obj.getJSONObject("after").optString("SHIP_CON_ID"));
pst.setString(13, obj.getJSONObject("after").optString("LAST_UPD"));
pst.setString(14, obj.getJSONObject("after").optString("X_CLOSE_DT"));
pst.setString(15, obj.getJSONObject("after").optString("X_SUB_STAT"));
pst.setString(16, obj.getJSONObject("after").optString("ORDER_NUM"));
pst.setString(17, obj.getJSONObject("after").optString("SOFT_DELETE"));
pst.setString(18, obj.getJSONObject("after").optString("LAST_UPD_BY"));
pst.setString(19, obj.getJSONObject("after").optString("REV_NUM"));
pst.setString(20, obj.getJSONObject("after").optString("ORDER_DT"));
pst.addBatch();
break;
case "U":
pst=con.prepareStatement(updateQuery);
pst.setString(1,obj.getJSONObject("after").optString("STATUS_CD"));
pst.setString(2, obj.getJSONObject("after").optString("INTEGRATION_ID"));
pst.setString(3, obj.getJSONObject("after").optString("X_CUST_REF"));
pst.setString(4, obj.getJSONObject("after").optString("REQ_SHIP_DT"));
pst.setString(5, obj.getJSONObject("after").optString("QUOTE_ID"));
pst.setString(6, obj.getJSONObject("after").optString("ACCNT_ID"));
pst.setString(7, obj.getJSONObject("after").optString("ACTIVE_FLG"));
pst.setString(8, obj.getJSONObject("after").optString("PROCESS_TIMESTAMP"));
pst.setString(9, obj.getJSONObject("after").optString("CONTACT_ID"));
pst.setString(10, obj.getJSONObject("after").optString("BU_ID"));
pst.setString(11, obj.getJSONObject("after").optString("SHIP_CON_ID"));
pst.setString(12, obj.getJSONObject("after").optString("LAST_UPD"));
pst.setString(13, obj.getJSONObject("after").optString("X_CLOSE_DT"));
pst.setString(14, obj.getJSONObject("after").optString("X_SUB_STAT"));
pst.setString(15, obj.getJSONObject("after").optString("ORDER_NUM"));
pst.setString(16, obj.getJSONObject("after").optString("SOFT_DELETE"));
pst.setString(17, obj.getJSONObject("after").optString("LAST_UPD_BY"));
pst.setString(18, obj.getJSONObject("after").optString("REV_NUM"));
pst.setString(19, obj.getJSONObject("after").optString("ORDER_DT"));
pst.setString(20, obj.getJSONObject("after").optString("ROW_ID"));
pst.addBatch();
break;
case "D":
pst=con.prepareStatement(deleteQuery);
pst.setString(1, obj.getJSONObject("after").optString("ROW_ID"));
pst.addBatch();
break;
}
if(++count % batchSize == 0) {
pst.executeBatch();
}
pst.executeBatch();
// con.commit();
pst.close();
}
}
//System.out.println(orderMongo);
con.close();
Connection secondcon=pds.getConnection("spring_kafka", "Aug2017");
secondcon.setAutoCommit(true);
System.out.println("Starting db op");
for (Entry<String, List<JSONObject>> entry : orderItemMongo.entrySet()) {
List<JSONObject> orderlist = entry.getValue();
for(JSONObject object:orderlist){
String op_type=object.optString("op_type");
switch(op_type){
case "I":
prest=secondcon.prepareStatement(insertItemQuery);
prest.setString(1, object.getJSONObject("after").optString("ASSET_ID"));
prest.setString(2, object.getJSONObject("after").optString("SERV_ACCNT_ID"));
prest.setString(3, object.getJSONObject("after").optString("REQ_SHIP_DT"));
prest.setString(4, object.getJSONObject("after").optString("X_PROD_DESC"));
prest.setString(5, object.getJSONObject("after").optString("SHIP_CON_ID"));
prest.setString(6, object.getJSONObject("after").optString("X_BES_STATUS"));
prest.setString(7, object.getJSONObject("after").optString("ROW_ID"));
prest.setString(8, object.getJSONObject("after").optString("STATUS_CD"));
prest.setString(9, object.getJSONObject("after").optString("ORDER_ID"));
prest.setString(10, object.getJSONObject("after").optString("COMPLETED_DT"));
prest.setString(11, object.getJSONObject("after").optString("LAST_UPD"));
prest.setString(12, object.getJSONObject("after").optString("SOFT_DELETE"));
prest.setString(13, object.getJSONObject("after").optString("INTEGRATION_ID"));
prest.setString(14, object.getJSONObject("after").optString("X_CDD"));
prest.setString(15, object.getJSONObject("after").optString("ACTION_CD"));
prest.setString(16, object.getJSONObject("after").optString("X_ORDER_ITEM_SUBSTATUS"));
prest.setString(17, object.getJSONObject("after").optString("X_APPT_REF"));
prest.setString(18, object.getJSONObject("after").optString("X_CANCELLED_DT"));
prest.setString(19, object.getJSONObject("after").optString("PROD_ID"));
prest.setString(20, object.getJSONObject("after").optString("SERVICE_NUM"));
prest.setString(21, object.getJSONObject("after").optString("MUST_DLVR_BY_DT"));
prest.setString(22, object.getJSONObject("after").optString("ROLLUP_FLG"));
prest.setString(23, object.getJSONObject("after").optString("ROOT_ORDER_ITEM_ID"));
prest.setString(24, object.getJSONObject("after").optString("BILL_ACCNT_ID"));
prest.setString(25, object.getJSONObject("after").optString("PROCESS_TIMESTAMP"));
prest.setString(26, object.getJSONObject("after").optString("QTY_REQ"));
prest.addBatch();
break;
case "U":
prest=secondcon.prepareStatement(updateItemQuery);
prest.setString(1, object.getJSONObject("after").optString("ASSET_ID"));
prest.setString(2, object.getJSONObject("after").optString("SERV_ACCNT_ID"));
prest.setString(3, object.getJSONObject("after").optString("REQ_SHIP_DT"));
prest.setString(4, object.getJSONObject("after").optString("X_PROD_DESC"));
prest.setString(5, object.getJSONObject("after").optString("SHIP_CON_ID"));
prest.setString(6, object.getJSONObject("after").optString("X_BES_STATUS"));
prest.setString(7, object.getJSONObject("after").optString("ORDER_ID"));
prest.setString(8, object.getJSONObject("after").optString("STATUS_CD"));
prest.setString(9, object.getJSONObject("after").optString("COMPLETED_DT"));
prest.setString(10, object.getJSONObject("after").optString("LAST_UPD"));
prest.setString(11,object.getJSONObject("after").optString("SOFT_DELETE"));
prest.setString(12, object.getJSONObject("after").optString("INTEGRATION_ID"));
prest.setString(13,object.getJSONObject("after").optString("X_CDD"));
prest.setString(14,object.getJSONObject("after").optString("ACTION_CD"));
prest.setString(15,object.getJSONObject("after").optString("X_ORDER_ITEM_SUBSTATUS"));
prest.setString(16, object.getJSONObject("after").optString("X_APPT_REF"));
prest.setString(17,object.getJSONObject("after").optString("X_CANCELLED_DT"));
prest.setString(18,object.getJSONObject("after").optString("PROD_ID"));
prest.setString(19, object.getJSONObject("after").optString("SERVICE_NUM"));
prest.setString(20, object.getJSONObject("after").optString("MUST_DLVR_BY_DT"));
prest.setString(21, object.getJSONObject("after").optString("ROLLUP_FLG"));
prest.setString(22, object.getJSONObject("after").optString("ROOT_ORDER_ITEM_ID"));
prest.setString(23, object.getJSONObject("after").optString("BILL_ACCNT_ID"));
prest.setString(24, object.getJSONObject("after").optString("PROCESS_TIMESTAMP"));
prest.setString(25, object.getJSONObject("after").optString("QTY_REQ"));
prest.setString(26, object.getJSONObject("after").optString("ROW_ID"));
prest.addBatch();
break;
case "D":
prest=secondcon.prepareStatement(deleteItemQuery);
prest.setString(1,object.getJSONObject("after").optString("ROW_ID"));
prest.addBatch();
break;
}
if(++count % batchSize == 0) {
prest.executeBatch();
}
prest.executeBatch();
//secondcon.commit();
prest.close();
}
}
secondcon.close();
System.out.println("Ending db op");
}
}
パブリック静的のOracleDataSourceのgetConnection()はClassNotFoundExceptionが、SQLExceptionがスロー{
OracleDataSource oracleDS =null;
oracleDS=new OracleDataSource();
oracleDS.setDriverType("oracle.jdbc.driver.OracleDriver");
oracleDS.setURL("jdbc:oracle:thin:@localhost:1521:orcl");
oracleDS.setUser("spring_kafka");
oracleDS.setPassword("Aug2017");
/*oracleDS.setConnectionCachingEnabled(true);
oracleDS.setConnectionCacheName("MYCACHE");
Properties cacheProps = new Properties();
cacheProps.setProperty("MinLimit", "1");
cacheProps.setProperty("MaxLimit", "500");
cacheProps.setProperty("InitialLimit", "1");
cacheProps.setProperty("ConnectionWaitTimeout", "5");
cacheProps.setProperty("ValidateConnection", "true");
oracleDS.setConnectionCacheProperties(cacheProps);
*/
/*Connection con=null;
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@10.50.84.85:1521:orcl","spring_kafka","Aug2017");*/
return oracleDS;
}
これをデバッグして、ループ内で何が起こっているのか確認しましたか? – MartinByers
'setDriverType'に渡される値は間違っていますが、URLを設定すると誤った値が無視されるためです。 'setDriverType'への呼び出しを削除する必要があります。 –