Skip to content

Commit

Permalink
Allow insert statements (from existing table to other) in mode -g
Browse files Browse the repository at this point in the history
  • Loading branch information
joheli committed May 12, 2021
1 parent a359798 commit 8bf2c73
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/main/java/dabadex/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@ public Query(ParametersG p) throws SQLException {
}

private void getData() throws SQLException {
lg.log(Level.FINE,"Sending query: " + p.getQuery());
String sql = p.getQuery();
lg.log(Level.FINE,"Sending query: " + sql);
if (!p.getStoredProcedure()) {
rs = st.executeQuery(p.getQuery());
// The query can be an insert statement without data to be uploaded (e.g. insert data from existing table to other).
// These queries do not return a resultset and therefore generate an error.
// To avoid that queries that contain "insert" are processed using executeUpdate.

// check if sql contains pattern 'insert'
if (sql.toLowerCase().contains("insert")) {
// if yes: process with executeUpdate
st.executeUpdate(sql);
} else {
// if no: process with executeQuery
rs = st.executeQuery(sql);
}
} else {
rs = conn.prepareCall(p.getQuery()).executeQuery();
rs = conn.prepareCall(sql).executeQuery();
}
dt = new DataReadIn(rs);
//st.close();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dabadex/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import utils.Utils;

public class Start implements Runnable {
public final static String version = "0.1.1";
public final static String version = "0.1.2";
public final static Logger LOGGER = Logger.getLogger("DaBaDExLog");
public static int cycle = 1;
private DaBaDExParam p;
Expand Down

0 comments on commit 8bf2c73

Please sign in to comment.