Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

ResultSet problem  RSS feed

 
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
 
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.
 
Ranch Hand
Posts: 1085
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
 
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...
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!