I've been testing the code over and over found that the issue is the single quote. As you can see in the query below, I used the single quote in the where clause. If I remove that I get a result but if I put it back even though the are rows that satisfies the filter it does not return anything. I also tried to use a view on this. Putting the where clause in the view and selecting the view directly and not using any filter. Still it does not return anything.
try {
Class.forName("org.postgresql.Driver").newInstance();
Connection Conn = DriverManager.getConnection("jdbc:postgresql://{ipaddress}/database?user=postgres&password=password");
Statement Stmt = Conn.createStatement();
String sqlCommand = "SELECT col1_timestamp , col2 FROM table WHERE col1_timestamp > '00:01:00' ";
ResultSet RS = Stmt.executeQuery(sqlCommand);
while (RS.next()) {
data.add(RS.getInt("col1_timestamp ")
+ "=>" + RS.getString("col2"));
}
// Clean up after ourselves
RS.close();
Stmt.close();
Conn.close();
}
catch (SQLException E) {
System.out.println("SQLException: " + E.getMessage());
System.out.println("SQLState: " + E.getSQLState());
System.out.println("VendorError: " + E.getErrorCode());
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
I also already tried:
String sqlCommand = "SELECT col1_timestamp, col2 FROM table "
+ " WHERE col2= ? AND (now() - col1_timestamp::timestamp with time zone) < interval ? ";
PreparedStatement preparedStatement = Conn.prepareStatement(sqlCommand);
preparedStatement.setString(1, "test");
preparedStatement.setTime(2, new Time(new Long(-28680000))); //String(2, "00:02:00");
Still does not work, instead it throws an error on the second parameter.
It's pretty simple task really but it always returns a blank value.
Any idea?