my dog learned polymorphism*
The moose likes JDBC and the fly likes sql query error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "sql query error" Watch "sql query error" New topic
Author

sql query error

kunal vermaa
Ranch Hand

Joined: Jun 27, 2009
Posts: 51
i m using this sql query in my project... is it showing an error..

sql query..


error is..

"Count field incorrect in SELECT command"

please help..
John Bengler
Ranch Hand

Joined: Feb 12, 2009
Posts: 133
Hi Kunal,

I don't know this error message, but I would change your sql statement to this:



Maybe your problem was that your subselect returns more than one value?


John
kunal vermaa
Ranch Hand

Joined: Jun 27, 2009
Posts: 51
thanks dude..
kunal vermaa
Ranch Hand

Joined: Jun 27, 2009
Posts: 51
can i use a variable directly into a SQL statement..


str is a String variable.. can it be done or i have to use the preparedStatement and setString() function..?
John Bengler
Ranch Hand

Joined: Feb 12, 2009
Posts: 133
If you think of dynamically composing your query you can do this.

But you should not. Working with parameters and setting these parameters enables the database to parse the select statement only once and then use the parsed statement with different parameters.

I'm not sure if this is an answer to your question...
kunal vermaa
Ranch Hand

Joined: Jun 27, 2009
Posts: 51
my query is dynamic.. the value of "str" is being taken from a jframe using getText() method. so the value will change according to the input on the jframe window by the user.. is it necessary to use the PreparedStatement or can i use the normal Statement object.. please explain..



will this create any error..??
John Bengler
Ranch Hand

Joined: Feb 12, 2009
Posts: 133
I think you could use both, with Statement I could think of something likethis:



As I wrote before I would prefer this:



kunal vermaa
Ranch Hand

Joined: Jun 27, 2009
Posts: 51
thanks.. i also prefer the 2nd method..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sql query error