954,198 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to get to next record on click of a button

hi every1
i m new to website development.
just learning it.
i have made a code in which i access my database(MS Access).
i m able to print the first record of the database on the page.
but i m not able to go to next record which i want to show on click of a button.
i dont want to use while(rs.next) as i dont want to show all the records at once.
the code i m writing is->

<%@ page import="java.sql.*" %>
<htmL>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dataSourceName="mydsn";
String dbURL="jdbc:odbc:" + dataSourceName;
Connection con= DriverManager.getConnection(dbURL,"","");
Statement s=con.createStatement();
s.execute("select * from web");
ResultSet rs;
rs=s.getResultSet() ;
rs.next();
%>
<body>
<script>
function getDetails()
{
rs.next()
}
</script>
<form method="post">
Website:<input type="text" value="<%=rs.getString(1) %>">
 <a href="http://www.daniweb.com/techtalkforums/<input">Url:<input</a>  type="text" value="<%=rs.getString(2) %>">
Category: <input type="text" value="<%=rs.getString(3) %>">
Description: <input type="text" value="<%=rs.getString(4) %>">
Search Engine->
Yahoo: <input type="text" value="<%=rs.getString(5) %>">
Google: <input type="text" value="<%=rs.getString(6) %>">
Altavista: <input type="text" value="<%=rs.getString(7) %>">
<input type="button" value="Next" onClick="getDetails()">
</form>
</body>
</html>
bhuvan83
Light Poster
29 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

Why don't you store whole databse into bean and then on button press request next set

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 901
 

bro thanks for ur reply.
but i dont know how to use beans.
can u show me a small code????

bhuvan83
Light Poster
29 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

nice explanation on wikipedia

bellow is how do I get data from my db about events in calendar

CalendarData[] eArr = new CalendarData[exists];
try
{				
	int i=0;
	strQuery = "select event_type, ev_date, ev_time, ev_description from calendar_events where userName='" + strUser + "' and cal_id='" + calId + "'";
	rs = stmt.executeQuery( strQuery);
	while( rs.next())
	{
		eArr[i] = new CalendarData();
		eArr[i].setEventType(rs.getString("event_type") );
		eArr[i].setEventDate(rs.getString("ev_date") );
		eArr[i].setEventTime(rs.getInt("ev_time") );
		eArr[i].setEventDescription(rs.getString("ev_description") );
		i++;					
	} // end while loop
	session.setAttribute("eventArray", eArr);
	CalendarData[] test = (CalendarData[]) session.getAttribute("eventArray");


Also do not connect to DB from JSP use servlets

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 901
 

thanks got the soln
:)

bhuvan83
Light Poster
29 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

Nice Nice! I used the Solution given by one of the members using the DAO Pattern! I agree with @peter_budo that having code in JSP does not solve problems quickly but rather call the methods from servlets or from separate java files. Great Thread! I also got a solution for one of my problems!


Thankz Once Again :-)

sagar_danceking
Junior Poster in Training
56 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You