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

added possibility to update table #613

Merged
merged 1 commit into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
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
25 changes: 23 additions & 2 deletions src/main/java/neqsim/util/database/NeqSimDataBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ public static void main(String[] args) {
// NeqSimDataBase.initH2DatabaseFromCSVfiles();
// NeqSimDataBase.initDatabaseFromCSVfiles();
NeqSimDataBase database = new NeqSimDataBase();
NeqSimDataBase.updateTable("COMP", "/workspaces/neqsim/src/main/resources/data/COMP.csv");


try (ResultSet dataSet = database.getResultSet("SELECT * FROM comp WHERE NAME='methane'")) {
dataSet.next();
Expand Down Expand Up @@ -430,6 +432,25 @@ public static boolean hasComponent(String compName) {
}
}

public static void updateTable(String tableName, String path) {
neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase();
String sqlString = "CREATE TABLE " + tableName + " AS SELECT * FROM CSVREAD('" + path + "')";
try {
database.execute("DROP TABLE " + tableName);
database.execute(sqlString);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (database.getStatement() != null) {
database.getStatement().close();
}
} catch (Exception ex) {
logger.error("error closing database.....", ex);
}
}
}

public static void initH2DatabaseFromCSVfiles() {
neqsim.util.database.NeqSimDataBase.connectionString =
"jdbc:h2:mem:neqsimthermodatabase;DB_CLOSE_DELAY=-1";
Expand All @@ -441,8 +462,8 @@ public static void initH2DatabaseFromCSVfiles() {
// Statement stmn = con.createStatement();
// stmn.execute(defaultDatabaseRootRoot)

String createCOMP = "CREATE TABLE comp AS SELECT * FROM CSVREAD('classpath:/data/COMP.csv')";
String createINTER = "CREATE TABLE inter AS SELECT * FROM CSVREAD('classpath:/data/INTER.csv')";
String createCOMP = "CREATE TABLE COMP AS SELECT * FROM CSVREAD('classpath:/data/COMP.csv')";
String createINTER = "CREATE TABLE INTER AS SELECT * FROM CSVREAD('classpath:/data/INTER.csv')";
String createElement =
"CREATE TABLE element AS SELECT * FROM CSVREAD('classpath:/data/element.csv')";
String create_iso6976 =
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/data/COMP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,4 @@
1184,"cis-14-DM-cy-C6","624-29-3","HC",147,"C",112.220000000,0.422182073,325.000000000,29.640000000,0.233980000,124.326013183,16.043000000,99.000000000,"Classic",66909.600000000,-68.400000000,0.897300000,-0.000513700,0.000000109,0.000000000,"log",39.205000000,-1324.400000000,-3.436600000,0.000031019,2.000000000,0.000000000,0.000000000,0.000000000,0.000000000,2.520000000,155.809006022,0.406998625,3,-26.870000000,1150.000000000,0.187000000,-0.000521000,-50500.000000000,2.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0,"solute",900.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.303000000,-0.000605000,-0.000003200,77.300000000,941.000000000,452.000000000,0.116656057,90.690000000,90.650000000,-74520.000000000,186.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,10200000.0000000,0.261000000,-0.147000000,0.222000000,0.000000000,0.100000000,0.585700000,-0.720600000,1.289900000,0.000000000,0.000000000,0.000000000,0.122841598,0.914470789,2.741978611,0,"0",0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,4.186260000,1,1.000000000,-6.680820000,0.000000000,9700,0.000015293,0.047920000,1594.000000000,0.012440000,2952.000000000,0.002317000,2777.000000000,1.076000000,1323.000000000,"yes",1.000000000,3.703900119,150.029998779,0.000000000,0.000000000,3.190710941,155.809006022,0.406998625,1.000000000,0,900.000000000,0.000621000,2760.000000000,0.421000000,1963.100000000,0.004048680,2636.750000000,0.295270000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.628820000,0.701140000,-0.784370000,0.000000000
1185,"trans-14-DM-cy-C6","2207-04-7","HC",147,"C",112.220000000,0.422182073,316.667016601,29.640000000,0.233980000,119.356011962,16.043000000,99.000000000,"Classic",66909.600000000,-68.400000000,0.897300000,-0.000513700,0.000000109,0.000000000,"log",39.205000000,-1324.400000000,-3.436600000,0.000031019,2.000000000,0.000000000,0.000000000,0.000000000,0.000000000,2.520000000,155.809006022,0.406998625,3,-26.870000000,1150.000000000,0.187000000,-0.000521000,-50500.000000000,2.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0,"solute",900.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.303000000,-0.000605000,-0.000003200,77.300000000,941.000000000,452.000000000,0.116656057,90.690000000,90.650000000,-74520.000000000,186.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,10200000.0000000,0.261000000,-0.147000000,0.222000000,0.000000000,0.100000000,0.585700000,-0.720600000,1.289900000,0.000000000,0.000000000,0.000000000,0.122841598,0.914470789,2.741978611,0,"0",0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,4.186260000,1,1.000000000,-6.680820000,0.000000000,9700,0.000015293,0.047920000,1594.000000000,0.012440000,2952.000000000,0.002317000,2777.000000000,1.076000000,1323.000000000,"yes",1.000000000,3.703900119,150.029998779,0.000000000,0.000000000,3.190710941,155.809006022,0.406998625,1.000000000,0,900.000000000,0.000621000,2760.000000000,0.421000000,1963.100000000,0.004048680,2636.750000000,0.295270000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.628820000,0.701140000,-0.784370000,0.000000000
1186,"PG","57-55-6","glycol",1186,"propyleneglycol",76.095000000,1.036000000,352.850000000,61.000000000,1.102000000,188.200000000,76.095000000,239.000000000,"Classic",32022.600000000,35.700000000,0.248400000,-0.000149700,0.000000030,0.000000000,"exp",13.629900000,6022.180000000,-28.250000000,0.000000000,0.000000000,2.308200000,0.215000000,0.248800000,0.000000000,3.626000000,481.800000000,0.000000000,3,-23.155244944,5694.484212533,0.023081509,0.000000000,57900.000000000,-19.290540000,29814.530000000,-0.019678500,0.013189000,0.031144000,0,"solvent",0.000000000,0.000000000,0.000000000,0.000000000,0.654009012,-3.955117195,3.671191916,0.517338954,-0.000798169,0.000000064,133.328650000,9958.000000000,904.000000000,0.000002420,260.150000000,260.150000000,-388000.000000000,324.000000000,21.400000000,0.000000000,0.000000000,0.000000000,0.000000000,1.315100000,0.251250000,719.700000000,0.218700000,0.000000000,82900000.0000000,0.427000000,0.000000000,0.000000000,0.000000000,1.117000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,4,"4C",0.000000000,0.000000000,0.019000000,17442.000000000,138360.000000000,6.750000000,0.937200000,108190.000000000,5.140000000,0.674400000,0.051400000,1,17.090887000,-7800.000000000,0.000000000,0,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,"no",0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,3.626000000,481.800000000,0.000000000,1.000000000,0,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,35540.000000000,436.780000000,-0.184860000,0.000000000,0.000000000,35540.000000000,436.780000000,-0.184860000,0.000000000,0.000000000,0.910030000,1.349960000,-1.890020000,151.817427819
1187,"ammonia","7664-41-7","other",1187,"Nh3",17.031,0.73,132.25,113.0,0.250,-33.35,17.031,99.000000000,"Classic",11133.000000000,39.192196000,-0.058081604,0.000350102,-0.000000369,1.276199e-10,"pow10",5.202770000,1580.080000000,239.500000000,0.000000000,0.000000000,1.700000000,0.215000000,0.200000000,0.000000000,3.626000000,481.800000000,0.000000000,3,-39.350000000,4826.000000000,0.109100000,-0.000113000,57900.000000000,-19.290500000,29814.500000000,-0.019678000,0.013189000,0.031144000,0,"solvent",0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-0.384000000,0.005250000,-0.000006370,73.069489067,3177.000000000,1000.000000000,0.006110000,175.500000000,175.500000000,-242000.000000000,189.000000000,30.585000000,0.000000000,0.000000000,0.000000000,0.000000000,2.288000000,0.268500000,512.640000000,0.245300000,0.000000000,52100000.0000000,0.320000000,-0.212000000,0.258000000,0.000000000,0.797000000,1.437100000,-0.799420000,0.327800000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,2,"2B",0.000000000,0.000000000,0.016100000,24591.000000000,40531.000000000,3.097800000,0.431020000,47052.000000000,3.300000000,0.903700000,0.044900000,1,17.387107060,-7582.406220000,0.000000000,0,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,"no",1.525500000,3.230000000,188.900000000,0.035176000,24106.443000000,3.626000000,481.800000000,0.000000000,1.000000000,0,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-12706.000000000,958.780000000,-5.233200000,0.013152000,0.000000000,105800.000000000,-362.230000000,0.937900000,0.000000000,0.000000000,1.224003000,-0.273500000,-0.398230000,87.543852818
1187,"ammonia","7664-41-7","other",1187,"NH3",17.031,0.73,132.25,113.0,0.250,-33.35,17.031,99.000000000,"Classic",11133.000000000,39.192196000,-0.058081604,0.000350102,-0.000000369,1.276199e-10,"pow10",5.202770000,1580.080000000,239.500000000,0.000000000,0.000000000,1.700000000,0.215000000,0.200000000,0.000000000,3.626000000,481.800000000,0.000000000,3,-39.350000000,4826.000000000,0.109100000,-0.000113000,57900.000000000,-19.290500000,29814.500000000,-0.019678000,0.013189000,0.031144000,0,"solvent",0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-0.384000000,0.005250000,-0.000006370,73.069489067,3177.000000000,1000.000000000,0.006110000,175.500000000,175.500000000,-242000.000000000,189.000000000,30.585000000,0.000000000,0.000000000,0.000000000,0.000000000,2.288000000,0.268500000,512.640000000,0.245300000,0.000000000,52100000.0000000,0.320000000,-0.212000000,0.258000000,0.000000000,0.797000000,1.437100000,-0.799420000,0.327800000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,2,"2B",0.000000000,0.000000000,0.016100000,24591.000000000,40531.000000000,3.097800000,0.431020000,47052.000000000,3.300000000,0.903700000,0.044900000,1,17.387107060,-7582.406220000,0.000000000,0,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,"no",1.525500000,3.230000000,188.900000000,0.035176000,24106.443000000,3.626000000,481.800000000,0.000000000,1.000000000,0,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,0.000000000,-12706.000000000,958.780000000,-5.233200000,0.013152000,0.000000000,105800.000000000,-362.230000000,0.937900000,0.000000000,0.000000000,1.224003000,-0.273500000,-0.398230000,87.543852818