Solved

Why this doesnt work?

Posted on 2003-11-12
14
328 Views
Last Modified: 2010-04-01
Hi,

I tried this in the JSP:

sql = "Select A.AssetNo, A.Currency, A.BuyPrice, A.SellPrice, A.NavPrice from  tblUTDISPLIST A "+
        "where A.id = "+
        "("+
        "select max(B.ID) from tblUTDISPLIST B where B.assetno = A.assetno "+
        ")";
ps2 = conn.prepareStatement(sql);
rs2 = ps2.executeQuery();

It returns the error: java.sql.SQLException: Invalid column name

But why when i querying it via SQLPlus there is not error occurs? What's wrong with my code?

Also can comment at:
http://www.experts-exchange.com/Databases/Oracle/Q_20796284.html
0
Comment
Question by:Ryan Chong
14 Comments
 
LVL 15

Expert Comment

by:jimmack
ID: 9738055
sql = "Select A.AssetNo, A.Currency, A.BuyPrice, A.SellPrice, A.NavPrice from  tblUTDISPLIST A "+

This line is missing and "AS" keyword:

sql = "Select A.AssetNo, A.Currency, A.BuyPrice, A.SellPrice, A.NavPrice from  tblUTDISPLIST AS A "+
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9738060
Oops.  So is this one:

>>       "select max(B.ID) from tblUTDISPLIST B where B.assetno = A.assetno "+

       "select max(B.ID) from tblUTDISPLIST AS B where B.assetno = A.assetno "+
0
 
LVL 49

Author Comment

by:Ryan Chong
ID: 9738235
sql = "Select A.AssetNo, A.Currency, A.BuyPrice, A.SellPrice, A.NavPrice from  tblUTDISPLIST As A "+
                          "where A.id = "+
                          "("+
                          "select max(B.ID) from tblUTDISPLIST As B where B.assetno = A.assetno "+
                          ")";

i got: ORA-00933: SQL command not properly ended ..
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9738400
Hmm.  On MySQL, I get a syntax error with the "select max..." line.  I don't think MySQL can handle the nested select.

Other than that, I can't see anything else wrong with this (though I'm no SQL expert!).

You can type this line in at a prompt and it works OK?
0
 
LVL 49

Author Comment

by:Ryan Chong
ID: 9738575
Problem resolved, actually there is nothing wrong with the SQL statement above! But it's something typo error on other parts. My bad... I must be very stressful recently doing multiple applications..

FYI, above is connect to an Oracle database, not MySQL

Sorry about that, will ask a question at CS to delete this question. Thanks for trying to help, jimmack, cheers
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9738601
;-)

For my information, does that SQL line work with out "As" keywords?
0
 
LVL 49

Author Comment

by:Ryan Chong
ID: 9739010
Unfortunately, no luck in Oracle. I got an error when try add "As" in the query in sqlplus, that's why i remove the "As" :-)

Are you know PL/SQL well, jimmack? Also can take a look on my other question. Damn! i need solve it asap.

Oh.. if no objection, i will post a request at CS to delete this question, is this fine with you?

cheers
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:jimmack
ID: 9739032
I'm afraid my knowledge of SQL is fairly limited.  I have recently had a similar problem to yours, where a complex query was involved, but I solved it programmatically.

If you want to delete this question, I don't have any problems with that ;-)
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9739670
>>Also can take a look on my other question. Damn! i need solve it asap
rogaut1 answered your question accurately, according to those jpg images you have posted.

If you have other problem, please give more detail.
0
 
LVL 49

Author Comment

by:Ryan Chong
ID: 9747468
You're right kennethxu, rogaut1 did give me great idea i miss out there, definitely will award pts to him, wil finalise and close the opening questions after the application is deployed. cheers
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9772045
Hi Jimmack.

>>For my information, does that SQL line work with out "As" keywords?

For your information. On Oracle Does not work the "AS" KeyWord it has to be without it.

Best regards
Javier
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9773387
Thanx Javier ;-)
0
 
LVL 49

Author Comment

by:Ryan Chong
ID: 10021100
Hi guys, time to close this question.

Suggestion: Delete this question
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 10021532
PAQed, with points refunded (250)

Computer101
E-E Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
issue with pdf generation 2 85
grep code 4 177
How to Post an If Statement in JSP 3 51
java operators 3 110
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
An analysis of the phishing scam that has been affecting Google users, along with steps to take for protection, as well as what to do if you receive one of the emails.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now