This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet problem

 
Indranil Guha Roy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
i am new to this forum....i have got some problem with conditional SELECT statement while working with JDBC.Following is my code fragment.

String query1="SELECT * FROM teacherdata WHERE code=' " + input + " ' ";
System.out.println(query1);
stmt1=con.createStatement();
ResultSet rst1=stmt1.executeQuery(query1);
while(rst1.next())
{
gs1=rst1.getString("code");
gs2=rst1.getString("name");
gs3=rst1.getString("age");
gs4=rst1.getString("sex");
gs5=rst1.getString("padd");
gs6=rst1.getString("tadd");
gs7=rst1.getString("email");
System.out.println(gs8);
gs9=rst1.getString("doj");
gs10=rst1.getString("dob");
}
the loop (while(rst1.next()) is not working that is it is not retriving values form the table "teacherdata" which is pointed by "project".please help
 
Heath Williams
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of using SELECT *
Specify your columns. Then retrive them our of the result set using the column name.
 
Indranil Guha Roy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for reply...but if u could be more specific about the syntax of SELECT statement (i.e how to use column names to retrive data), it would have been more helpfull.
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indranil,

you should have posted this in JDBC Forum.
any way does the query printed by System.out.println(query1) gives you result.
If yes then make sure you are connected to correct database or check if there is any exception you are ignoring.

Shailesh
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indranil accidentally posted this in a new thread:

Originally posted by Indranil Guha Roy:
thanks for reply...but if u could be more specific about the syntax of SELECT statement (i.e how to use column names to retrive data), it would have been more helpfull.


Anyway, moving to JDBC...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic