By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 1,876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Simple SQLJ program ....

P: n/a
A very simple piece of SQLJ:

try
{
#sql [sqlj4context] sqlj4_iterator = {SELECT PHONENO FROM
DB2ADM.EMPLOYEE WHERE WORKDEPT = 'D11'};

while(sqlj4_iterator.next())
{
System.out.println(sqlj4_iterator.phoneno());
if (sqlj4_iterator.phoneno() == "2890")
{
System.out.println("YES!!");
}
}
sqlj4_iterator.close();
#sql [sqlj4context] {COMMIT};
sqlj4context.close();
} catch (SQLException sqlexcp)

The output generated is:

6423
4510
3782
2890
1682
2986
4501
0942
0672

Why is "YES" not produced in the output when phone no. 2890 appears in
the output? PHONENO is defined as CHAR(4) in the table.

TIA
Raquel.
Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Raquel" <ra****************@yahoo.com> wrote in message
news:9a**************************@posting.google.c om...
A very simple piece of SQLJ:

try
{
#sql [sqlj4context] sqlj4_iterator = {SELECT PHONENO FROM
DB2ADM.EMPLOYEE WHERE WORKDEPT = 'D11'};

while(sqlj4_iterator.next())
{
System.out.println(sqlj4_iterator.phoneno());
if (sqlj4_iterator.phoneno() == "2890")
{
System.out.println("YES!!");
}
}
sqlj4_iterator.close();
#sql [sqlj4context] {COMMIT};
sqlj4context.close();
} catch (SQLException sqlexcp)

The output generated is:

6423
4510
3782
2890
1682
2986
4501
0942
0672

Why is "YES" not produced in the output when phone no. 2890 appears in
the output? PHONENO is defined as CHAR(4) in the table.


Stored Procedures run in a background process so they cannot do screen
writes. If you want to get diagnostics of this kind, you will have to write
them to a file. You don't need anything fancy; a simple flat file written to
your file system is all you need.

Rhino
Nov 12 '05 #2

P: n/a
Hi Rhino, this is not a stored procdure. A simple SQLJ program. As I
mentioned in the original mail, all the phone nos. are correctly
getting displayed on the screen....then why not 'YES' !!!

Thanks.
Raquel.
Nov 12 '05 #3

P: n/a

"Raquel" <ra****************@yahoo.com> wrote in message
news:9a**************************@posting.google.c om...
Hi Rhino, this is not a stored procdure. A simple SQLJ program. As I
mentioned in the original mail, all the phone nos. are correctly
getting displayed on the screen....then why not 'YES' !!!

Oops, sorry, I just assumed it was a stored procedure because of the stored
procedures problems you had earlier.

Your problem this time is your use of the '==' operator. The correct way to
tell if a String is equal to a given value is the equals() method of the
String class. Instead of this:

if (sqlj4_iterator.phoneno() == "2890")

you should have:

if (sqlj4_iterator.phoneno().equals("2890"))

The '==' operator is fine for numbers that are stored in Java primitives
like short, int, long, float, and double but it is NOT appropriate for
Strings. Make the change I suggested and your problem should go away.

Rhino
Nov 12 '05 #4

P: n/a
Very correct Rhino. That indeed was the problem.

Thanks
Raquel.
Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.