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