wood burning stoves 2.0*
The moose likes JDBC and the fly likes Resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Resultset" Watch "Resultset" New topic
Author

Resultset

Vineet kumar Gupta
Greenhorn

Joined: Dec 18, 2011
Posts: 16

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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Dec 18, 2011
Posts: 16
Thank you tim maroos... It is working
Vineet kumar Gupta
Greenhorn

Joined: Dec 18, 2011
Posts: 16

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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Dec 18, 2011
Posts: 16
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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Dec 18, 2011
Posts: 16
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

Joined: Dec 18, 2011
Posts: 16
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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Dec 18, 2011
Posts: 16
Okk friend...you are right...first I have to know about the jtable ..and.its structure ....thank you for your guideline...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Resultset
 
Similar Threads
MS Access Insert - last row missing
accessing values from servlets to jsp
Result set type is TYPE_FORWARD_ONLY
set checkbox "checked" when a value in an selectbox changes
Result Set problems