Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resultset

 
Vineet kumar Gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

How to retrive multyple rows from a data set ...i am getting only last row because of
While(rs.next())
(
Jtextfield1.settext(rs.getString("name"))
jtextfield2.setText(rs.getString("name"))
)
In both text fields I am getting same result .
only last row record just beacuse of while loop

But I want to set 1row and 2 row records respctvly..
What should I do...?
 
Tim Moores
Bartender
Posts: 2789
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ResultSets are record-oriented - you can only ever access a single record at a time. You'll need to change your display logic accordingly. Something like:
 
Vineet kumar Gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you tim maroos... It is working
 
Vineet kumar Gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

what is the method of setting records in a jtable....lyk for jtextfield is...
Jtextfield1.setText(rs.getString("name"))..

What will be for jTable.?
What will be the way of retriving records from resultset and placing these on a jtable....

 
Tim Moores
Bartender
Posts: 2789
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "retriving records from resultset" that the code above does not already do? Is this question purely about how to use JTable?
 
Vineet kumar Gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I am a new lerner of java and working on a project..my faculty not helps me..thats why I am here... I even dont know how to use a jtable.... I do not want to create it by coding... I have draged and dropped already a table from palette in netbeans.... Number of rows and columns are same as in sql table ...now I want to show sql table in jtable....
How can I achive this.... guide me...
 
Tim Moores
Bartender
Posts: 2789
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to learn something, then don't use a GUI builder like NetBeans. As you discovered, it doesn't help you understand the Swing classes - which in this case you need to. Start here: http://docs.oracle.com/javase/tutorial/ui/index.html
 
Vineet kumar Gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are saying that I should design the project in notepad by coding....? I do not have enough time friend...i hv almost completed it but ...the scenario is ....i hv a table in sql named student...now I hv a button say "view all" by which I want to see all the records of student table.....please guide me..
 
Vineet kumar Gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go to this page I want to use jtable like it...there is a table view

http://docs.oracle.com/javase/tutorial/ui/overview/demo.html
 
Tim Moores
Bartender
Posts: 2789
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can write code any way you want; I wouldn't use Notepad, but at a minimum something that understand Java syntax, like Vim. But if you already know NetBeans you might just as well use that. Either way, I don't see how you could get around learning the Swing classes if you want to create an app with a Swing GUI. At the least, rather obviously, you'll need to understand JTable: http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
 
Vineet kumar Gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okk friend...you are right...first I have to know about the jtable ..and.its structure ....thank you for your guideline...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic