what is this query doing?

for(rset = conn.executeQ(OurQuery); rset.next(); items.put(rset.getString(1), rset.getString(2)));

rset = ResultSet

conn= Connection

Items --> private Hashtable items;

here is OurQuery

OurQuery = " \t \tselect LABEL_CODE ,NVL(INITCAP(DECODE(" + lang + ",1,DESC_EN_TX,DESC_AR_TX)),'N... AVAIL') " + "\t from FORM_USER_LABEL \t\t\t\t\t\t\t" + " \twhere UPPER(FORM_ID) \t\t= UPPER('" + v_frm + "')" + " \tAND USER_ID \t\t= " + v_user;

here is the executeQ method

public synchronized ResultSet executeQ(String s)

throws SQLException

{

Object obj = null;

ResultSet resultset = null;

try

{

if(conn.isClosed())

ConnectDB();

stmt = conn.createStatement();

resultset = stmt.executeQuery(s);

}

catch(Exception exception)

{

System.out.println(exception);

}

return resultset;

}

[923 byte] By [ali_hammada] at [2007-11-27 8:22:45]
«« Batch Limit
»» MHP
# 1
I don't know and I don't care.Please use PreparedStatements and do away with that nonsense. Get rid of the tabs to. What is the point of that supposed to be?
cotton.ma at 2007-7-12 20:11:31 > top of Java-index,Java Essentials,Java Programming...
# 2
My guess is throwing an exception.
floundera at 2007-7-12 20:11:31 > top of Java-index,Java Essentials,Java Programming...
# 3
I have no choice.. I have been assigned this task to .. to look into the code and make changes as they are requested.. \This code ant written by me... Its s*** but i cant do any thing
ali_hammada at 2007-7-12 20:11:31 > top of Java-index,Java Essentials,Java Programming...
# 4
Just make me understand this line of code... for(rset = conn.executeQ(OurQuery); rset.next(); items.put(rset.getString(1), rset.getString(2)));
ali_hammada at 2007-7-12 20:11:31 > top of Java-index,Java Essentials,Java Programming...
# 5

> Just make me understand this line of code...

>

>

> for(rset = conn.executeQ(OurQuery); rset.next();

> items.put(rset.getString(1), rset.getString(2)));

It's terrible.

I REFUSE to help you. Because among other problems the ResultSet is not being closed properly there.

This will lead to SERIOUS problems down the road in your project. It will run out of memory and crash.

So I cannot in good conscience help you. Sorry.

cotton.ma at 2007-7-12 20:11:31 > top of Java-index,Java Essentials,Java Programming...
# 6

I can say only what the query does

First i will spit this query into an understandable manner.

1.select LABEL_CODE , // This selects the label code

2.NVL(INITCAP(DECODE(" + lang + ",1,DESC_EN_TX,DESC_AR_TX)),'N... AVAIL') // The above part of the query uses three functions one is NVL,INITCAP and Decode.

The NVL will convert when the query returns NULL to an user provided value i.e "N... AVAIL".

The InitCAP will convert the Starting letters of each word to Upper case

The Decode works like an if condition i.e

Decode(value,condition,if condition is true,if condition is false)

In your example, where decode works like

if(lang == 1)

DESC_EN_TX

else

DESC_AR_TX

and the remaining part of the query it converts to upper case and compares with a where condition.

if you still have doubts, first check for Decode option in oracle tutorial how it works then check the query.

it is not necessary to keep the "\t" inside the query

harish.suna at 2007-7-12 20:11:31 > top of Java-index,Java Essentials,Java Programming...
# 7
@harish.sun : Thank you very much.. \Good explaination..
ali_hammada at 2007-7-12 20:11:31 > top of Java-index,Java Essentials,Java Programming...