Board index » jbuilder » A JDBC/SQL Syntax Problem

A JDBC/SQL Syntax Problem


2003-09-05 10:45:28 AM
jbuilder0
I'm trying to query a database table based on a keyword the user enters.
try
{
keySearch = connect.prepareStatement
("SELECT * FROM Inventory WHERE ItemDesc LIKE ?");
}
The above works, but I want wildcards before & after the parameter. I've
tried variations of standard SQL (ex.):
try
{
keySearch = connect.prepareStatement
("SELECT * FROM Inventory WHERE ItemDesc LIKE '%?%'");
}
I keep getting a null pointer exception error whenever I add a % or the
single quotes.
Can anyone give me a hand on this? It would be greatly appreciated.
Thanks,
Dave
XXXX@XXXXX.COM
 
 

Re:A JDBC/SQL Syntax Problem

Hi,
I had the same problem (very long ago),
as far as I remember, the problem is because the single quotes,
prepared statement doesn't substitute question marks between single quotes,
and keeps the whole string between single quotes as a non-parameteric string
(and I now think this should be the same way), I'm not sure but I think I
solved my problem by using something like:
... WHERE ItemDesc LIKE '%' || ? || '%'
note: || is concate operator in Oracle DBMS.
Amir Pashazadeh
"Darlene & Dave" < XXXX@XXXXX.COM >wrote in message
Quote
I'm trying to query a database table based on a keyword the user enters.

try
{
keySearch = connect.prepareStatement
("SELECT * FROM Inventory WHERE ItemDesc LIKE ?");
}

The above works, but I want wildcards before & after the parameter. I've
tried variations of standard SQL (ex.):

try
{
keySearch = connect.prepareStatement
("SELECT * FROM Inventory WHERE ItemDesc LIKE '%?%'");
}

I keep getting a null pointer exception error whenever I add a % or the
single quotes.

Can anyone give me a hand on this? It would be greatly appreciated.

Thanks,


Dave
XXXX@XXXXX.COM