• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems with Select statement...

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I am having a problem with a select statement I am executing in my program. I have successfully executed select statements using variables, but now I just want to use a specific value. When I execute the statement, I keep getting a "Result set has no current row". Could someone look at my code to see what I am doing wrong? I'm sure it's something simple I am overlooking, but can't pinpoint it.
Thanks in advance!

[ June 17, 2002: Message edited by: Jennifer Sohl ]
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jennifer
The way you have it written the newid variable is hardcoded into the string as the word 'newid'.
rs = stmt.executeQuery("Select * from projectmaster where id# = newid");
Assuming newid is a a variable that has already been assigned a value then something like this should work:
rs = stmt.executeQuery("Select * from projectmaster where id# = " & newid);
hope that helps
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave,
Thanks for the reply. Not sure if you read my post before or after I edited it. The way I have it now is "Select * from projectmaster where id# = 'newid'".
'newid' is not a variable it is supposed to be an actual value itself.
When I tried taking out the single quotes, I received an error stating "Invalid column name 'newid'.
So I actually want the word 'newid' in the query.
When I run the following statement in SQL Query Analyzer:
Select * from projectmaster where id# = 'newid'
I get 1 row returned.
Any ideas?
Thanks again!
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Jennifer
I read it before you edited it
Could it be because your trying to print the 1st thing in the resultset before you've moved the pointer with next() ?
That's the first thing that comes to mind. If the query executes ok and you get a result in the analyser then there is nothing wrong with the query itself. If using next() doesn't work then I guess the next question would be if you've made any changes to the type of cursor you use or an other changes not shown in your code.
Let me know if that works...
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh my gosh, I feel so stupid. Thanks for pointing that out to me. Don't tell anyone ok??
Thanks again! I owe you one.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Couple of Questions :
What DBMS are you using ?
TRY THIS :
Define a variable :
String newId="";
//Put whatever value you want
eg. newId = "Hi";
then Use following Select :
"Select * From ProjectMaster Where Id#='"+newId+"'";
which replaces your sql
stmt.executeQuery("Select * from projectmaster where id# = 'newid'");System.out.println("String=" + rs.getString(1));
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't tell anyone what

Next time I'm wherever you are or you're in Cleveland you can buy my silence with a beer or a coke.
glad you got it working
 
reply
    Bookmark Topic Watch Topic
  • New Topic