473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Simple SQLJ program ....

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
4 1483

"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
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

"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
Very correct Rhino. That indeed was the problem.

Thanks
Raquel.
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bernard Dhooghe | last post by:
DB2 UDB V8.1 Fixpak 4 AIX 5.1 CLASSPATH: /usr/opt/db2_08_01/java/db2jcc.jar:/usr/opt/db2_08_01/java/db2jcc_license_cu.jar:/usr/opt/db2_08_01/java/sqlj.zip:/usr/java131/jre/lib/rt.jar: Program:...
0
by: Peter | last post by:
Hello, I am trying to create a Java program that uses blob's with sqlj. At first I am trying to do this on udb windows. After that I should work also on db2 on zos from the windows platform...
0
by: Raquel | last post by:
ok, this is a SQL program program that runs fine. What does it mean to have iterator declared outside the class declaration (from a Java perspective, what are we doing here??)...I was under the...
10
by: Raquel | last post by:
UDB PE 8.1 on Win XP. ok, this function caused a lot of grief today. My stored procedures are java stored procedures, all FENCED and directly placed in \sqllib\function directory (not built into...
2
by: Raquel | last post by:
UDB V8.1.3 on XP. While trying out SQLj procedures, I just 'compile' my stored procedure code (by command sqlj program-name.sqlj) and run it. That's it. So, how and when is db2profc and all the...
12
by: Rhino | last post by:
I am having an odd problem: the sqlj command on my system doesn't work. I am running DB2 (LUW) V8 (FP8) on WinXP. I haven't done an sqlj program since Version 6 of DB2 (LUW) so I checked the...
7
by: Jean-Marc Blaise | last post by:
Hi, The dev center calls sqlj.DB2_UPDATEJARINFO ('JMARC.JMB','JMB','file:JMB.sqlj') to update the sqlj routine source. I tried in CLP from the directory containing jar and sqlj files (Windows...
0
by: shibubaby | last post by:
Hi All, I am trying to compile some embedded SQL using the SQLJ in DB2 environment. My setup is as follows. 1) Fedora Core 5 2)IBM DB2 V8.2 I installed both the client/admin tools in the DB2...
1
by: vasilip | last post by:
I'm trying to insert large polygon data via sql statement. since the data was over 32k I had to use sqlj to insert my data. I made a class that inserts the data. ran sqlj, generated the .java...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.