Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

query is not getting executed

 
Hrishikesh Maluskar
Ranch Hand
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone tell me why the following query is not getting executed..i am using struts2 and MYSQL

 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the issue you are having? Any exception.. ?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only get data if there is something to get
 
Hrishikesh Maluskar
Ranch Hand
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2577
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Hrishikesh Maluskar
Ranch Hand
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic