Здравствуйте.
С недавнего времени начал избавляться от так называемого спагетти кода в JSP и переходить на отдельный front end и back end
в результате преобразований пришел к такому виду на back end
Calendar fDATETIME = Calendar.getInstance(); // creates calendar
Calendar tDATETIME = Calendar.getInstance();
SimpleDateFormat ShortDateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
SimpleDateFormat DateFormatForSQLOracle = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
fDATETIME.setTime(ShortDateFormat.parse(DATETIME_FROM));
tDATETIME.setTime(ShortDateFormat.parse(DATETIME_TO));
String sql="select * from EVENTS a where a.TIME_CREATE between ? and ? and lower(a.original_data) like ?";
try
{
Class.forName(ClassDriverName);
} catch (ClassNotFoundException e)
{
throw new RuntimeException(e.getMessage());
}
try (Connection conn = DriverManager.getConnection(DB_URL_Connection, DB_UserName, DB_Password)) {
PreparedStatement preparedStatement = conn.prepareStatement(sql);
preparedStatement.setTimestamp(1, java.sql.Timestamp.valueOf(DateFormatForSQLOracle.format(fDATETIME.getTime())));
preparedStatement.setTimestamp(2, java.sql.Timestamp.valueOf(DateFormatForSQLOracle.format(tDATETIME.getTime())));
preparedStatement.setString(3, "%Хост :%".toLowerCase())
}
ResultSet result = preparedStatement.executeQuery();
while (result.next()) {
System.out.println(result.getString("ID"));
sql_EVENT_OK = " select to_char(t.ELT) as ELT, to_char(t.IDX) as IDX /*, t.**/\n" +
" from\n" +
" EVENT_CUSTOM_ATTRIBUTES t\n" +
" where\n" +
" t.event_id=?\n" +
" and t.idx=?\n";
preparedStatement = conn.prepareStatement(sql_EVENT_OK);
preparedStatement.setString(1, result.getString("ID"));
preparedStatement.setString(2, "StateChangedByEvent");
ResultSet result_ELT= preparedStatement.executeQuery();
while (result_ELT.next()) {
sql_EVENT_OK=" SELECT *\n" +
" FROM EVENTS a\n" +
" where\n" +
" a.id=?";
preparedStatement = conn.prepareStatement(sql_EVENT_OK);
preparedStatement.setString(1, result_ELT.getString("ELT"));
ResultSet result_EVENT_OK = preparedStatement.executeQuery();
while (result.next()) {
System.out.println(result_EVENT_OK .getTimestamp("TIME_CREATED"));
}
}
conn.close();
Насколько оптимально использовать такой способ?
Жду критических замечаний...