print sql statements on failure

This commit is contained in:
Paul Trowbridge 2022-10-20 12:12:41 -04:00
parent 1cb878bdb2
commit ac59b46e1f

View File

@ -35,8 +35,7 @@ public class jrunner {
Integer cols = null;
String[] dtn = null;
msg = "Help:";
msg = msg + nl + "jrunner version 0.28";
msg = "jrunner version 0.29";
msg = msg + nl + "-scu source jdbc url";
msg = msg + nl + "-scn source username";
msg = msg + nl + "-scp source passowrd";
@ -186,6 +185,7 @@ public class jrunner {
e.printStackTrace();
System.exit(0);
}
//-------------------------------build & execute sql-------------------------------------------------------------
try {
while (rs.next()) {
r++;
@ -193,10 +193,8 @@ public class jrunner {
nr = "";
for (int i = 1; i <= cols; i++){
nc = rs.getString(i);
Boolean dnull = false;
if (rs.wasNull()) {
nc = "NULL";
dnull = true;
} else {
switch (dtn[i]){
case "VARCHAR":
@ -240,10 +238,11 @@ public class jrunner {
}
nr = nr + nc;
}
//System.out.println(nr);
//add a comma to the end of the VALUES block to accomodate a new row
if (sql!="") {
sql = sql + ",";
}
//add the new row to the VALUES block
sql = sql + "(" + nr + ")";
if (r == 250){
r = 0;
@ -255,20 +254,24 @@ public class jrunner {
System.out.println(t);
} catch (SQLException e) {
e.printStackTrace();
System.out.println(sql);
System.exit(0);
}
sql = "";
}
}
sql = "INSERT INTO " + dt + " VALUES " + "\n" + sql;
//System.out.println(sql);
try {
stmtd = dcon.createStatement();
stmtd.executeUpdate(sql);
System.out.println(t);
} catch (SQLException e) {
e.printStackTrace();
System.exit(0);
//if the sql is not empty, execute
if (sql != "") {
sql = "INSERT INTO " + dt + " VALUES " + "\n" + sql;
try {
stmtd = dcon.createStatement();
stmtd.executeUpdate(sql);
System.out.println(t);
} catch (SQLException e) {
e.printStackTrace();
System.out.println(sql);
System.exit(0);
}
}
} catch (SQLException e) {
e.printStackTrace();