Compare commits

...

13 Commits

4 changed files with 109 additions and 9 deletions

View File

@ -26,6 +26,8 @@ dependencies {
//jdbc drivers
implementation 'org.postgresql:postgresql:42.5.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 {

View File

@ -4,6 +4,7 @@ import java.util.*;
import java.nio.file.Files;
import java.nio.file.Path ;
import java.nio.file.Paths;
import java.time.*;
public class jrunner {
//static final String QUERY = "SELECT * from rlarp.osm LIMIT 100";
@ -19,6 +20,7 @@ public class jrunner {
String sq = "";
String dt = "";
Boolean trim = true;
Boolean clear = true;
Integer r = 0;
Integer t = 0;
String sql = "";
@ -34,8 +36,10 @@ public class jrunner {
String[] getv = null;
Integer cols = null;
String[] dtn = null;
Timestamp tsStart = null;
Timestamp tsEnd = null;
msg = "jrunner version 0.35";
msg = "jrunner version 0.41";
msg = msg + nl + "-scu source jdbc url";
msg = msg + nl + "-scn source username";
msg = msg + nl + "-scp source passowrd";
@ -45,6 +49,7 @@ public class jrunner {
msg = msg + nl + "-sq path to source query";
msg = msg + nl + "-dt fully qualified name of destination table";
msg = msg + nl + "-t trim text";
msg = msg + nl + "-c clear target table";
msg = msg + nl + "--help info";
//---------------------------------------parse args into variables-------------------------------------------------
@ -60,6 +65,7 @@ public class jrunner {
scn = args[i+1];
break;
//source password
//import java.time.*;
case "-scp":
scp = args[i+1];
break;
@ -95,6 +101,9 @@ public class jrunner {
case "-t":
trim = true;
break;
case "-c":
clear = true;
break;
case "-v":
System.out.println(msg);
return;
@ -161,6 +170,9 @@ public class jrunner {
//----------------------------------------open resultset------------------------------------------------------------
try {
stmt = scon.createStatement();
stmt.setFetchSize(10000);
tsStart = Timestamp.from(Instant.now());
System.out.println(tsStart);
rs = stmt.executeQuery(sq);
//while (rs.next()) {
// System.out.println(rs.getString("x"));
@ -191,39 +203,67 @@ public class jrunner {
e.printStackTrace();
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-------------------------------------");
//-------------------------------build & execute sql-------------------------------------------------------------
try {
sql = "";
while (rs.next()) {
r++;
t++;
nr = "";
for (int i = 1; i <= cols; i++){
switch (dtn[i]){
switch (dtn[i].toUpperCase()){
case "VARCHAR":
nc = rs.getString(i).replace("'","''");
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).replace("'","''");
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).replace("'","''");
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;
@ -239,19 +279,21 @@ public class jrunner {
}
break;
case "TIME":
nc = rs.getString(i).replace("'","''");
nc = rs.getString(i);
if (rs.wasNull() || nc == null) {
nc = "NULL";
break;
}
nc.replaceAll("'","''");
nc = "'" + nc + "'";
break;
case "TIMESTAMP":
nc = rs.getString(i).replace("'","''");
nc = rs.getString(i);
if (rs.wasNull() || nc == null) {
nc = "NULL";
break;
}
nc.replaceAll("'","''");
nc = "'" + nc + "'";
break;
case "BIGINT":
@ -323,6 +365,11 @@ public class jrunner {
e.printStackTrace();
}
System.out.println(" rows written");
System.out.println("");
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();
}
}

6
copy_to_apt.sh Executable file
View File

@ -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"

45
readme.md Normal file
View File

@ -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/
```