字符串 qLink = "";
qLink = "INSERT INTO trackgps.queclinklogs(Supplier,NtwProtocol,IMEI,log,DBTIME)" +
"VALUES" +
"(" +
"'" + supplier + "',"+
"'" + protocol + "',"+
"'" + failedQIMEI + "',"+
"'" + failedQLog + "',"+
"'" + currentQuecTimestamp + "'" +
")," +
"(" +
"'" + supplier + "'" + "," +
"'" + protocol + "'" + "," +
"'" + QuecLinkIMEI + "'" + "," +
"'" + data2 + "'" + "," +
"'" + currentQuecTimestamp + "'" +
")";
Statement stmtLink = connQ.createStatement();
stmtLink.execute(qLink);
stmtLink.close();
字符串字节消耗 = "";
bytesconsumption = "INSERT INTO test_backoffice.carrierDataConsumption(IMEI,beginMonth,endMonth,dataConsumed,month,year) VALUES" +
"(" +
"'"+ QuecLinkIMEI + "'" + "," +
"NOW()" + "," +
"NOW()" + "," +
"'"+ totalBytesConsumed + "'," +
"MONTH(NOW())" + "," +
"YEAR(NOW())" +
") ON DUPLICATE KEY UPDATE endMonth = NOW(), dataConsumed = dataConsumed + " + totalBytesConsumed;
Statement stmtbytesconsumption;
stmtbytesconsumption = connQ.createStatement();
stmtbytesconsumption.execute(bytesconsumption);
stmtbytesconsumption.close();
字符串 qdebug = "";
qdebug = "INSERT INTO trackgps.rawdata(Module,SubModule,IMEI,listenerTime,msg)" +
"VALUES" +
"(" +
"'"+ "LISTENER TCP" + "'" + "," +
"'"+ SubMod + "'" + "," +
"'"+ identifier + "'" + "," +
"'"+ listendatetime + "'" + "," +
"'"+ msg + "'" +
")";
Statement stmtqdebug = conn.createStatement();
stmtqdebug.execute(qdebug);
stmtqdebug.close();
无论如何在一个java语句中执行这三个插入?而不是创建 3 个执行和 3 个关闭的语句?
我还有其他问题,我应该使用 Statements 还是 PrepareStatements?