Answer the question
In order to leave comments, you need to log in
Why is the error ORA-01008: not all variables bound?
Hello.
trying to send parametrized select
String sql=
"select *\n"+
"FROM EVENTS a \n"+
" where \n"
" a.TIME_RECEIVED BETWEEN ? AND ?\n"
" and a.original_data like ?\n"
" order by a.time_created"
try (Connection conn = DriverManager.getConnection(DB_URL_Connection, DB_UserName, DB_Password)) {
PreparedStatement prepStmt = conn.prepareStatement(sql);
prepStmt.setDate(1, new java.sql.Date(fDATETIME.getTime()));
prepStmt.setDate(2, new java.sql.Date(tDATETIME.getTime()));
prepStmt.setString(3, "%Хост: %");
ResultSet result = prepStmt.executeQuery(sql);
Answer the question
In order to leave comments, you need to log in
the solution looks like this
changed the data type to TimeStamp and sql was superfluous in ResultSet result = prepStmt.executeQuery(sql);
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));
try (Connection conn = DriverManager.getConnection(DB_URL_Connection, DB_UserName, DB_Password)) {
PreparedStatement prepStmt = conn.prepareStatement(sql);
prepStmt.setTimestamp(1, java.sql.Timestamp.valueOf(DateFormatForSQLOracle.format(fDATETIME.getTime())));
prepStmt.setTimestamp(2, java.sql.Timestamp.valueOf(DateFormatForSQLOracle.format(tDATETIME.getTime())));
prepStmt.setString(3, "%Хост: %");
ResultSet result = prepStmt.executeQuery();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question