Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed bug in update database table #811

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/main/java/neqsim/util/database/NeqSimDataBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,24 +424,29 @@ public static void updateTable(String tableName) {
updateTable(tableName, "data/" + tableName + ".csv");
}

/**
/**
* Drops and re-creates table from contents in csv file.
*
* @param tableName Name of table to replace
* @param path Path to csv file to
*/
public static void updateTable(String tableName, String path) {
URL url = NeqSimDataBase.class.getClassLoader().getResource(path);
if (url == null) {
try {
java.nio.file.Paths.get(path);
} catch (Exception e) {
throw new RuntimeException(new neqsim.util.exception.InvalidInputException("NeqSimDataBase",
"updateTable", "path", "- Resource " + path + " not found"));
}
try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase()) {
neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase();
try {
database.execute("DROP TABLE IF EXISTS " + tableName);
String sqlString = "CREATE TABLE " + tableName + " AS SELECT * FROM CSVREAD('" + url + "')";
String sqlString = "CREATE TABLE " + tableName + " AS SELECT * FROM CSVREAD('" + path + "')";
database.execute(sqlString);
} catch (Exception ex) {
updateTable(tableName);
logger.error("Failed updating table " + tableName, ex);
throw new RuntimeException(new neqsim.util.exception.InvalidInputException("NeqSimDataBase",
"updateTable", "path", "- Resource " + path + " not found"));
}
}

Expand Down
Loading