Answer the question
In order to leave comments, you need to log in
What would be the best way to use this method?
Hello.
Recently, I began to get rid of the so-called spaghetti code in JSP and switch to a separate front end and back end
as a result of transformations I came to this look on the 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();
Answer the question
In order to leave comments, you need to log in
try
{
Class.forName(ClassDriverName);
} catch (ClassNotFoundException e)
{
throw new RuntimeException(e.getMessage());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question