aspose file tools*
The moose likes JDBC and the fly likes Problems with Select statement... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problems with Select statement..." Watch "Problems with Select statement..." New topic
Author

Problems with Select statement...

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
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 ]
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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


Dave
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
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

Joined: May 10, 2001
Posts: 3244
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

Joined: Feb 28, 2001
Posts: 455
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.
Shivade Sanjay
Greenhorn

Joined: Apr 09, 2002
Posts: 6
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

Joined: May 10, 2001
Posts: 3244
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems with Select statement...