File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes query is not getting executed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "query is not getting executed" Watch "query is not getting executed" New topic
Author

query is not getting executed

Hrishikesh Maluskar
Ranch Hand

Joined: Jun 19, 2008
Posts: 115
can anyone tell me why the following query is not getting executed..i am using struts2 and MYSQL



SCJP 1.5
www.licexpadvice.com
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

What is the issue you are having? Any exception.. ?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

how can you be sure that it is not being executed, as opposed to not returning any results?
Have you tried outputting the query and running it directly against the database?
as an outside chance: You're not using the Jdbc-ODBC bridge are you?
Hrishikesh Maluskar
Ranch Hand

Joined: Jun 19, 2008
Posts: 115
the query runs directly in database.

in java it gives the following exception

java.sql.SQLException: Before start of result set
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

my code is as follows

David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You can only get data if there is something to get
Hrishikesh Maluskar
Ranch Hand

Joined: Jun 19, 2008
Posts: 115
there are two records in the database , which should be displayed. I feel that that the query is not getting executed at all.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Hi.
Your code is not going to fetch two records from the database. Calling getString(0) and getString(1) is not the mechanism to retrieve two rows.
You should loop the resultset using while(rst.next()) {...}

Try to find out when (at which line in your source) the java.sql.SQLException is thrown, and why.


Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
Hrishikesh Maluskar
Ranch Hand

Joined: Jun 19, 2008
Posts: 115
java.sql.SQLException: Column Index out of range, 0 < 1.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)

i am getting the above exception after writing this code.

Fatih Keles
Ranch Hand

Joined: Sep 01, 2005
Posts: 182
As in most database also jdbc drivers start counting from 1 not 0.

it is stated in exception :
java.sql.SQLException: Column Index out of range, 0 < 1.


Regards,

Fatih.
Neel Bera
Greenhorn

Joined: Oct 13, 2009
Posts: 2
Hi,

I tried a program with database connection and tried retrieving values from DB. The following is the code inside while loop after successfully querying the DB



I just stored the value in a String object "n". Then displayed the object "n".

also when i tried


then I am getting a SQLException :
[Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index



I am not sure if this is the solution to the prob, but you can give it a try.Also, if you are getting the correct solution please do post it.

Thank you.
Neel (Newbie)
Hrishikesh Maluskar
Ranch Hand

Joined: Jun 19, 2008
Posts: 115
Thanks everybody this problem is solved..i had written rst.getString(0) , changing it to rst.getString(1) worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: query is not getting executed
 
Similar Threads
Passing data from text file to table.
NoResultException
Prepared statements question
Why resultSet is null?
error in running HQL Query