Escape Characters ?

folks

i am trying to form a String variable with the below SQL code , Please let me know how to deal with escape characters

select col1,col2,col3 from table1

where col5 = param1

and upper(col6) = 'A'

and col7= 'TABLE2 NAME'

and col8 LIKE UPPER('param2%');

param1 and param2 are input parameters

regrds

mathew

[378 byte] By [kmathewma] at [2007-11-27 8:08:46]
# 1
can some one look into this
kmathewma at 2007-7-12 19:51:45 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
When you say "escape characters" do you mean the Java escape characters or the SQL escape characters or what? A more detailed problem description would help. Right now we don't even have basic information like whether you have compile-time or run-time errors.
DrClapa at 2007-7-12 19:51:45 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
its SQL escape characters
kmathewma at 2007-7-12 19:51:45 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

In case of Oracle, you can build sql statement as follows:

select col1,col2,col3 from table1 where col5 = param1 and upper(col6) = 'A' and col7= 'TABLE2 NAME'

and col8 LIKE UPPER('param2\%') ESCAPE '\'

Hope this is what you are looking for..!

Let me know how it goes

spoosarlaa at 2007-7-12 19:51:45 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

You are almost always better off with a parameterized query using PreparedStatement. This is better for the database since it can cache the execution plan for the query, and better for your java code since you don't have to escape quotes in strings or format dates.

PreparedStatement stmt = con.prepareStatement(

"select col1,col2,col3 from table1 " +

"where col5 = ?" +

"and upper(col6) = ?" +

"and col7= ?" +

"and col8 LIKE UPPER(?)");

stmt.setString(1, param1);

stmt.setString(2, "A");

stmt.setString(3, "TABLE2 NAME");

stmt.setString(4, param2 + "%");

ResultSet rs = stmt.executeQuery();

Jemiah

fishninja007a at 2007-7-12 19:51:45 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...