Home » Category » Java Essentials

Java Essentials: "=" problem in query

300| Mon, 24 Sep 2007 14:45:00 GMT| unknown_citizena| Comments (9)

my prepared statement is using this SQL query...

"select * from myTable where ( time<=? and time=>?) order by time"

this query giving is invalid syntax errorb for "=" sign.... if i remove the "=" sign , this works fine.

but i want to keep the "=" sign in my query. How ? what should be the proper sql query with the "=" sign ?

Keywords & Tags: query, java, essentials

URL: http://java.itags.org/java-essentials/16/
 
«« Prev - Next »» 9 helpful answers below.
Come to think of it, isn't "time" a reserved word? If you use a reserved word as a field name (not advisable) you have to quote it. I think with MS/SQL the appropriate quote is backtick as in `TIME`.

malcolmmca | Fri, 13 Jul 2007 13:17:00 GMT |

>= not =>

mlka | Fri, 13 Jul 2007 13:17:00 GMT |

I'd use"where time between ? and ?"Otherwiise use the NOT operator.

malcolmmca | Fri, 13 Jul 2007 13:17:00 GMT |

> I'd use

>

> "where time between ? and ?"

>

> Otherwiise use the NOT operator.

info: CORE3282: stdout: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver

for JDBC][SQLServer]Incorrect syntax near the keyword 'between'.

Let me try the other one

unknown_citizena | Fri, 13 Jul 2007 13:17:00 GMT |

Odd. Works on Oracle. But then oracle SQL can be a bit weird.

malcolmmca | Fri, 13 Jul 2007 13:17:00 GMT |

it works with ms sql 2000 as well.

watercolour__yesa | Fri, 13 Jul 2007 13:17:00 GMT |

.....time<=? time>=?this also producesinfo: CORE3282: stdout: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Line 1: Incorrect syntax near '='.

unknown_citizena | Fri, 13 Jul 2007 13:17:00 GMT |

> .....time<=? time>=?and

annie79a | Fri, 13 Jul 2007 13:17:00 GMT |

I am sure that this database has an equivalent to "<=" or ">="; however, you can always spell it out yourself:where ((time<? OR time=?) AND (time>? OR time=?))

jbisha | Fri, 13 Jul 2007 13:17:00 GMT |

Java Essentials Hot Answers

Java Essentials New questions

Java Essentials Related Categories