Enter your email address:

Delivered by FeedBurner


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retrieve database table values in loop using jsp
12-12-2011, 11:24 PM
Post: #1
Big Grin Retrieve database table values in loop using jsp
Here you are going to know about how to retrieve database table values in a loop ie assign each row to a different variable so that you can access it for any operation.

First Create a table in mysql or any database:
Create table no(name varchar(20));


Now write the jsp code as follows to retrieve the values and print it.

<%
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/s2sgateway","username","password");
Statement st=con.createStatement();
String[] namediffer=new String[100];
ResultSet rs=st.executeQuery("select * from no");
int i=0;
while(rs.next())
{
namediffer[i]=rs.getString(1);
out.println(namediffer[i]);
i++;
}%>


So namediffer[0] will hold first value
namediffer[1] will hold second value and so on try this and ask question if any doubt.

Happy coding
Find all posts by this user
Add Thank You Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies Views: Last Post
Sad how to import a csv file values in to database using jsp rajasri 2 2,427 02-20-2012 12:17 PM
Last Post: rajesh2407
Lightbulb compare current time with database retrieved time in jsp rajasri 0 703 12-19-2011 05:17 PM
Last Post: rajasri
Thumbs Up Display combo box value/Database value on same JSP page rajasri 0 863 12-19-2011 04:57 PM
Last Post: rajasri
Its My Birthday! Display database value in jsp page rajasri 0 1,322 12-14-2011 11:43 AM
Last Post: rajasri
Its My Birthday! How to pass and get values in href as parameters in Jsp rajasri 0 2,549 12-13-2011 12:04 AM
Last Post: rajasri
Tongue Servlet example for printing random values rajasri 0 512 12-12-2011 06:48 PM
Last Post: rajasri
  Servlet example for printing random values admin 0 1,037 11-28-2011 06:30 PM
Last Post: admin

Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Like Our Facebook Page