Обсуждение: Syntax of LIKE in PreparedStatement

Поиск
Список
Период
Сортировка

Syntax of LIKE in PreparedStatement

От
"Mihai Gheorghiu"
Дата:
When I need to translate a PostgreSQL query such as:
SELECT * FROM tbl WHERE name = 'Smith';
into a PreparedStatement, I use something such as:
sql = con.prepareStatement("SELECT * FROM tbl WHERE name = ?");
sql.setString(1, myVariable);

How do I translate
SELECT * FROM tbl WHERE name LIKE '%Smith%';
I'm not sure what happens to ' and %.

Thank you all.



Re: Syntax of LIKE in PreparedStatement

От
Dave Cramer
Дата:
Mihai

just set the prepared statement to

"select * from table where name like ?"

and then do a setString(1,"%Smith%")

Dave
On Fri, 2002-04-05 at 16:49, Mihai Gheorghiu wrote:
> When I need to translate a PostgreSQL query such as:
> SELECT * FROM tbl WHERE name = 'Smith';
> into a PreparedStatement, I use something such as:
> sql = con.prepareStatement("SELECT * FROM tbl WHERE name = ?");
> sql.setString(1, myVariable);
>
> How do I translate
> SELECT * FROM tbl WHERE name LIKE '%Smith%';
> I'm not sure what happens to ' and %.
>
> Thank you all.
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>
>