Compare commits
16 Commits
Author | SHA1 | Date |
---|---|---|
Paul Trowbridge | b3a9151eff | |
Paul Trowbridge | e7b7d1bbba | |
Paul Trowbridge | 24fad6aa04 | |
Paul Trowbridge | b816399cba | |
Paul Trowbridge | fe39c6a2ae | |
pt | c67c7b1360 | |
Paul Trowbridge | 05508d8b26 | |
Paul Trowbridge | 1050930667 | |
Paul Trowbridge | 509873e60b | |
Paul Trowbridge | 2245ef1ba2 | |
Paul Trowbridge | c7884f3605 | |
Paul Trowbridge | efd922b2e0 | |
Paul Trowbridge | 3b4af2bf47 | |
Paul Trowbridge | 0615163fad | |
Paul Trowbridge | cf5abeddbe | |
Paul Trowbridge | e60a92cfdc |
|
@ -26,6 +26,8 @@ dependencies {
|
||||||
//jdbc drivers
|
//jdbc drivers
|
||||||
implementation 'org.postgresql:postgresql:42.5.0'
|
implementation 'org.postgresql:postgresql:42.5.0'
|
||||||
implementation 'net.sf.jt400:jt400:11.0'
|
implementation 'net.sf.jt400:jt400:11.0'
|
||||||
|
implementation 'com.microsoft.sqlserver:mssql-jdbc:9.2.0.jre8'
|
||||||
|
implementation 'com.microsoft.sqlserver:mssql-jdbc_auth:9.2.0.x64'
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path ;
|
import java.nio.file.Path ;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.time.*;
|
||||||
|
|
||||||
public class jrunner {
|
public class jrunner {
|
||||||
//static final String QUERY = "SELECT * from rlarp.osm LIMIT 100";
|
//static final String QUERY = "SELECT * from rlarp.osm LIMIT 100";
|
||||||
|
@ -19,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 = "";
|
||||||
|
@ -34,8 +36,10 @@ public class jrunner {
|
||||||
String[] getv = null;
|
String[] getv = null;
|
||||||
Integer cols = null;
|
Integer cols = null;
|
||||||
String[] dtn = null;
|
String[] dtn = null;
|
||||||
|
Timestamp tsStart = null;
|
||||||
|
Timestamp tsEnd = null;
|
||||||
|
|
||||||
msg = "jrunner version 0.32";
|
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";
|
||||||
|
@ -45,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-------------------------------------------------
|
||||||
|
@ -60,6 +65,7 @@ public class jrunner {
|
||||||
scn = args[i+1];
|
scn = args[i+1];
|
||||||
break;
|
break;
|
||||||
//source password
|
//source password
|
||||||
|
//import java.time.*;
|
||||||
case "-scp":
|
case "-scp":
|
||||||
scp = args[i+1];
|
scp = args[i+1];
|
||||||
break;
|
break;
|
||||||
|
@ -95,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;
|
||||||
|
@ -140,6 +149,7 @@ public class jrunner {
|
||||||
|
|
||||||
//-------------------------------------------establish connections-------------------------------------------------
|
//-------------------------------------------establish connections-------------------------------------------------
|
||||||
//source database
|
//source database
|
||||||
|
System.out.println("------------open database connections---------------------");
|
||||||
try {
|
try {
|
||||||
scon = DriverManager.getConnection(scu, scn, scp);
|
scon = DriverManager.getConnection(scu, scn, scp);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -147,18 +157,22 @@ public class jrunner {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
System.out.println(" ✅ source database");
|
||||||
//destination database
|
//destination database
|
||||||
try {
|
try {
|
||||||
dcon = DriverManager.getConnection(dcu, dcn, dcp);
|
dcon = DriverManager.getConnection(dcu, dcn, dcp);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.out.println("issue connecting to desctination:");
|
System.out.println("issue connecting to destination:");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
System.out.println(" ✅ destination database");
|
||||||
//----------------------------------------open resultset------------------------------------------------------------
|
//----------------------------------------open resultset------------------------------------------------------------
|
||||||
System.out.println("issue connecting to desctination:");
|
|
||||||
try {
|
try {
|
||||||
stmt = scon.createStatement();
|
stmt = scon.createStatement();
|
||||||
|
stmt.setFetchSize(10000);
|
||||||
|
tsStart = Timestamp.from(Instant.now());
|
||||||
|
System.out.println(tsStart);
|
||||||
rs = stmt.executeQuery(sq);
|
rs = stmt.executeQuery(sq);
|
||||||
//while (rs.next()) {
|
//while (rs.next()) {
|
||||||
// System.out.println(rs.getString("x"));
|
// System.out.println(rs.getString("x"));
|
||||||
|
@ -183,65 +197,118 @@ public class jrunner {
|
||||||
try {
|
try {
|
||||||
for (int i = 1; i <= cols; i++){
|
for (int i = 1; i <= cols; i++){
|
||||||
dtn[i] = rs.getMetaData().getColumnTypeName(i);
|
dtn[i] = rs.getMetaData().getColumnTypeName(i);
|
||||||
System.out.println(rs.getMetaData().getColumnName(i) + ": " + dtn[i]);
|
System.out.println(" * " + rs.getMetaData().getColumnName(i) + ": " + dtn[i]);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
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++;
|
||||||
nr = "";
|
nr = "";
|
||||||
for (int i = 1; i <= cols; i++){
|
for (int i = 1; i <= cols; i++){
|
||||||
nc = rs.getString(i);
|
switch (dtn[i].toUpperCase()){
|
||||||
if (nc == null) {
|
case "VARCHAR":
|
||||||
nc = "NULL";
|
nc = rs.getString(i);
|
||||||
}
|
if (rs.wasNull() || nc == null) {
|
||||||
else {
|
nc = "NULL";
|
||||||
if (rs.wasNull()) {
|
break;
|
||||||
nc = "NULL";
|
|
||||||
} else {
|
|
||||||
switch (dtn[i]){
|
|
||||||
case "VARCHAR":
|
|
||||||
nc = rs.getString(i).replace("'","''");
|
|
||||||
if (trim) { nc = nc.trim();}
|
|
||||||
nc = "'" + nc + "'";
|
|
||||||
break;
|
|
||||||
case "CLOB":
|
|
||||||
nc = rs.getString(i).replace("'","''");
|
|
||||||
if (trim) { nc = nc.trim();}
|
|
||||||
nc = "'" + nc + "'";
|
|
||||||
break;
|
|
||||||
case "CHAR":
|
|
||||||
nc = rs.getString(i).replace("'","''");
|
|
||||||
if (trim) { nc = nc.trim();}
|
|
||||||
nc = "'" + nc + "'";
|
|
||||||
break;
|
|
||||||
case "DATE":
|
|
||||||
nc = "'" + rs.getString(i) + "'";
|
|
||||||
if (nc == "'1/1/0001 12:00:00 AM'") {
|
|
||||||
nc = "NULL";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "TIME":
|
|
||||||
nc = "'" + rs.getString(i).replace("'","''") + "'";
|
|
||||||
break;
|
|
||||||
case "BIGINT":
|
|
||||||
nc = rs.getString(i);
|
|
||||||
default:
|
|
||||||
if (rs.getString(i) != "") {
|
|
||||||
nc = rs.getString(i);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
nc = "NULL";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
nc = nc.replaceAll("'","''");
|
||||||
|
if (trim) { nc = nc.trim();}
|
||||||
|
nc = "'" + nc + "'";
|
||||||
|
break;
|
||||||
|
case "TEXT":
|
||||||
|
nc = rs.getString(i);
|
||||||
|
if (rs.wasNull() || nc == null) {
|
||||||
|
nc = "NULL";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nc = nc.replaceAll("'","''");
|
||||||
|
if (trim) { nc = nc.trim();}
|
||||||
|
nc = "'" + nc + "'";
|
||||||
|
break;
|
||||||
|
case "CHAR":
|
||||||
|
nc = rs.getString(i);
|
||||||
|
if (rs.wasNull() || nc == null) {
|
||||||
|
nc = "NULL";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nc = nc.replaceAll("'","''");
|
||||||
|
if (trim) { nc = nc.trim();}
|
||||||
|
nc = "'" + nc + "'";
|
||||||
|
break;
|
||||||
|
case "CLOB":
|
||||||
|
nc = rs.getString(i);
|
||||||
|
if (rs.wasNull() || nc == null) {
|
||||||
|
nc = "NULL";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nc = nc.replaceAll("'","''");
|
||||||
|
if (trim) { nc = nc.trim();}
|
||||||
|
nc = "'" + nc + "'";
|
||||||
|
break;
|
||||||
|
case "DATE":
|
||||||
|
nc = rs.getString(i);
|
||||||
|
if (rs.wasNull() || nc == null) {
|
||||||
|
nc = "NULL";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nc = "'" + nc + "'";
|
||||||
|
if (nc == "'1/1/0001 12:00:00 AM'") {
|
||||||
|
nc = "NULL";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "TIME":
|
||||||
|
nc = rs.getString(i);
|
||||||
|
if (rs.wasNull() || nc == null) {
|
||||||
|
nc = "NULL";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nc.replaceAll("'","''");
|
||||||
|
nc = "'" + nc + "'";
|
||||||
|
break;
|
||||||
|
case "TIMESTAMP":
|
||||||
|
nc = rs.getString(i);
|
||||||
|
if (rs.wasNull() || nc == null) {
|
||||||
|
nc = "NULL";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nc.replaceAll("'","''");
|
||||||
|
nc = "'" + nc + "'";
|
||||||
|
break;
|
||||||
|
case "BIGINT":
|
||||||
|
nc = rs.getString(i);
|
||||||
|
if (rs.wasNull() || nc == null) {
|
||||||
|
nc = "NULL";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
nc = rs.getString(i);
|
||||||
|
if (rs.wasNull() || nc == null) {
|
||||||
|
nc = "NULL";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (i != 1){
|
if (i != 1){
|
||||||
nr = nr + ",";
|
nr = nr + ",";
|
||||||
|
@ -297,6 +364,12 @@ public class jrunner {
|
||||||
System.out.println("issue closing connections");
|
System.out.println("issue closing connections");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
System.out.println("");
|
System.out.println(" rows written");
|
||||||
|
tsEnd = Timestamp.from(Instant.now());
|
||||||
|
System.out.println(tsStart);
|
||||||
|
System.out.println(tsEnd);
|
||||||
|
//long time = Duration.between(tsStart, tsEnd).toMillis();
|
||||||
|
//System.out.println("time elapsed: " + time);
|
||||||
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
sudo cp app/build/distributions/app.zip /opt/
|
||||||
|
sudo rm -rf /opt/app/
|
||||||
|
sudo unzip /opt/app.zip -d /opt/
|
||||||
|
sudo rm /opt/app.zip
|
||||||
|
sudo chown $USER:$USER -R /opt/app/
|
||||||
|
export JR="/opt/app/bin/app"
|
|
@ -0,0 +1,45 @@
|
||||||
|
## install java jdk.
|
||||||
|
find downloads page and get latest tarball.
|
||||||
|
https://www.oracle.com/java/technologies/downloads/
|
||||||
|
|
||||||
|
```
|
||||||
|
wget https://download.oracle.com/java/19/latest/jdk-19_linux-x64_bin.tar.gz
|
||||||
|
tar -xvf downloaded_file
|
||||||
|
```
|
||||||
|
move the extracted folder to /opt
|
||||||
|
put the extracted location in your path variable
|
||||||
|
```
|
||||||
|
export JAVA_HOME=/opt/jdk-19.0.1
|
||||||
|
export PATH=$PATH:$JAVA_HOME/bin
|
||||||
|
```
|
||||||
|
|
||||||
|
`java --version` to test
|
||||||
|
|
||||||
|
## install gradle
|
||||||
|
https://docs.gradle.org/current/userguide/installation.html
|
||||||
|
go to gradle.org and find the latest bin.zip file (burried in the `direct link` hyperlink)
|
||||||
|
```
|
||||||
|
wget https://services.gradle.org/distributions/gradle-7.6-bin.zip
|
||||||
|
unzip -d /opt/gradle gradle-7.6-bin.zip
|
||||||
|
```
|
||||||
|
point to the gradle install
|
||||||
|
```
|
||||||
|
export PATH=$PATH:/opt/gradle/gradle-7.6/bin
|
||||||
|
gradle -v` to validate
|
||||||
|
```
|
||||||
|
|
||||||
|
## clone this repo
|
||||||
|
clone
|
||||||
|
`git clone https://gitea.hptrow.me/pt/jrunner.git`
|
||||||
|
|
||||||
|
build
|
||||||
|
gradle build`
|
||||||
|
|
||||||
|
copy to opt for use
|
||||||
|
```
|
||||||
|
sudo cp app/build/distributions/app.zip /opt/
|
||||||
|
sudo rm -rf /opt/app/
|
||||||
|
sudo unzip /opt/app.zip -d /opt/
|
||||||
|
sudo rm /opt/app.zip
|
||||||
|
sudo chown ptrowbridge:ptrowbridge -R /opt/app/
|
||||||
|
```
|
Loading…
Reference in New Issue