Hello, my friends,
I’m facing an issue to Refresh the screen and its data table after receiving data using Oracle JDBC and execute its query and save it in ArrayList. In the view controller (openDialog), there is an event called request action using data context to set data one by one (for loop) into the Data container, and everything going well and set the data successfully in the data container but when I click “save” one record would appear in the data table and after click refresh, all record will be reloaded.
Here is some sample for my code:
Service#
ArrayList outputString = new ArrayList<>();
//step1 load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection con= DriverManager.getConnection("");
//step3 create the statement object
Statement stmt = con.createStatement();
//step4 execute query
ResultSet rs = stmt.executeQuery("")
while(rs.next()){
Dto dto = new Dto();
getDto.setId(rs.getString(1));
getDto.setName(rs.getString(2));
}
//step5 close the connection object
con.close();
rs.close();
return outputString;
}
Controller#
private DataContianer getData(Data request) {
if (result != null) {
for (int i = 0; i < result.size(); i++) {
request = dataContext.create(Data.class);
request.setId(result.get(i).get_Id());
request.setName(result.get(i).get_Name());
}
@ Subscribe("requestAction")
private void onRequestAction(Action.ActionPerformedEvent event){
String Number = numberFeild.getValue();
Boolean callingStatus = false;
DataContianer request = new DataContianer();
if (criteriaField.getValue() == "ID") {
result = GetService.GetDataById(Number);
if(result.size() != 0) {
getDataContianer(request);
callingStatus = true;
}
}
If (callingStatus) {
getScreenData().getDataContext().commit();
getScreenData().loadAll();
closeWithDiscard();
}
}
This is a part of my code, and as you see that I’m doing loadAll and getDataContext.Comment but I’m getting one empty record and one record appears instead of 18 records.
Please help me first to refresh the Data table in the view then I need some advice to my code and is there another professional way to execute the oracle query and insert data directly to the data container without all there loops.
One thing that I didn’t mention I re-edit the screen of Editor to have different control and we make create action for requesting and retrieving data.
All the best,