ODBC bridge ->MSSQL ->prepared Like statements

Hi,

are any known problems when using the JDBC/ODBC bridge, with MS_SQL and then using PreparedStatements with LIKE.

We where going to do this, we had something like :

PreparedStatement pstmt = conn.prepareStatement("Select * from Employees where LastName like ? ");

pstmt.setString(1, 'A%');

rs = pstmt.executeQuery();

And it did not work. (returned no rows).

We "solved" the problem by installing another JDBC driver, and it works fine (same code/data).

So I just like to know if there is a way to go around this or if this...

Thanx

-reynir@hugsmidjan.is

[643 byte] By [ReynirH] at [2007-9-26 1:52:50]
# 1
change the following: pstmt.setString(1, 'A%');topstmt.setString(1, "A%");single quotes are used for chars and may be messing up your search value when the SQL is created.Jamie
jlrober at 2007-6-29 3:03:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
another thought: Is the wildcard character '%' or '*' ? I think it is '*' for M$ isn't it? I don't deal with M$ (thankfully) using JDBC. try:pstmt.setString(1, "A*");
jlrober at 2007-6-29 3:03:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

that would not be according to the JDBC specs. the wildcard car is % for JDBC (should not matter which DB ure accessing), and then u have _ (underscore) .

But then again we also tried exact match with the like keyword but it did nor return anything.

our problem was the LIKE keyword on the ODBC bridge, but not some other parts of the sql statement.

thanx anyways.

-r

ReynirH at 2007-6-29 3:03:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
This might interest you: http://developer.java.sun.com/developer/bugParade/bugs/4331045.html
jlrober at 2007-6-29 3:03:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
thats not a totall answer but still almost a whole one.my problem did not seem to be with wildcards, but it was with the keyword like (we tried exact match also)-thx
ReynirH at 2007-6-29 3:03:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
thats not a totall answer but still almost a whole one.my problem did not seem to be with wildcards, but it was with the keyword LIKE (we tried exact match also)-thx
ReynirH at 2007-6-29 3:03:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
I know 'like' works with MS SQL, but I wasn't using prepared statements when I did it.
jschell at 2007-6-29 3:03:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...