add an option to clear out the target table prior to moving data

This commit is contained in:
Paul Trowbridge 2023-02-01 16:29:53 -05:00
parent 24fad6aa04
commit e7b7d1bbba

View File

@ -20,6 +20,7 @@ public class jrunner {
String sq = ""; String sq = "";
String dt = ""; String dt = "";
Boolean trim = true; Boolean trim = true;
Boolean clear = true;
Integer r = 0; Integer r = 0;
Integer t = 0; Integer t = 0;
String sql = ""; String sql = "";
@ -38,7 +39,7 @@ public class jrunner {
Timestamp tsStart = null; Timestamp tsStart = null;
Timestamp tsEnd = null; Timestamp tsEnd = null;
msg = "jrunner version 0.40"; msg = "jrunner version 0.41";
msg = msg + nl + "-scu source jdbc url"; msg = msg + nl + "-scu source jdbc url";
msg = msg + nl + "-scn source username"; msg = msg + nl + "-scn source username";
msg = msg + nl + "-scp source passowrd"; msg = msg + nl + "-scp source passowrd";
@ -48,6 +49,7 @@ public class jrunner {
msg = msg + nl + "-sq path to source query"; msg = msg + nl + "-sq path to source query";
msg = msg + nl + "-dt fully qualified name of destination table"; msg = msg + nl + "-dt fully qualified name of destination table";
msg = msg + nl + "-t trim text"; msg = msg + nl + "-t trim text";
msg = msg + nl + "-c clear target table";
msg = msg + nl + "--help info"; msg = msg + nl + "--help info";
//---------------------------------------parse args into variables------------------------------------------------- //---------------------------------------parse args into variables-------------------------------------------------
@ -99,6 +101,9 @@ public class jrunner {
case "-t": case "-t":
trim = true; trim = true;
break; break;
case "-c":
clear = true;
break;
case "-v": case "-v":
System.out.println(msg); System.out.println(msg);
return; return;
@ -198,9 +203,24 @@ public class jrunner {
e.printStackTrace(); e.printStackTrace();
System.exit(0); System.exit(0);
} }
//-------------------------clear the target table if requeted----------------------------------------------------
if (clear) {
System.out.println("------------clear target table----------------------------");
sql = "DELETE FROM " + dt;
try {
stmtd = dcon.createStatement();
System.out.println(" " + sql);
stmtd.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
System.out.println(sql);
System.exit(0);
}
}
System.out.println("------------row count-------------------------------------"); System.out.println("------------row count-------------------------------------");
//-------------------------------build & execute sql------------------------------------------------------------- //-------------------------------build & execute sql-------------------------------------------------------------
try { try {
sql = "";
while (rs.next()) { while (rs.next()) {
r++; r++;
t++; t++;