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) %>"><br>
Url:<input type="text" value="<%=rs.getString(2) %>"><br>
Category: <input type="text" value="<%=rs.getString(3) %>"><br>
Description: <input type="text" value="<%=rs.getString(4) %>"><br>
Search Engine-><br>
Yahoo: <input type="text" value="<%=rs.getString(5) %>"><br>
Google: <input type="text" value="<%=rs.getString(6) %>"><br>
Altavista: <input type="text" value="<%=rs.getString(7) %>"><br>
<input type="button" value="Next" onClick="getDetails()">
</form>
</body>
</html>

You're trying to directly mix a process across two different environments. It won't work like that.

That page executes twice as two different 'programs' so to speak. Firstly; it's a JSP? program; which is able to connect to your database (on a server) and to 'transform' the page somewhat. After the JSP process has run; your page will look something like this:

<html>
<body>
<script>
function getDetails()
{
rs.next()
}
</script>
<form method="post">
Website:<input type="text" value="example"><br>
Url:<input type="text" value="http://example.com"><br>
Category: <input type="text" value="generic"><br>
Description: <input type="text" value="these values came from your database"><br>
Search Engine-><br>
Yahoo: <input type="text" value="is a search engine"><br>
Google: <input type="text" value="owns the web"><br>
Altavista: <input type="text" value="used to be more popular"><br>
<input type="button" value="Next" onClick="getDetails()">
</form>
</body>
</html>

That page is sent to a web browser; where it is interpretted as an "HTML and Javascript" program. Clearly; there's no reference anywhere to the 'rs' object that you were using at the server; and even if there was; you wouldn't be able to keep a local connection to your database active on a remote machine.

The easiest way you can do what you want to do; is to send information to your server side script by whatever means; telling it which record to display. You could do that by reloading the page with a query string variable when the 'next' button is clicked; and then using that in the JSP program as a record index... Or using an AJAX method to send a request from a Javascript method (running in a user's browser) to a JSP program (running on the server) that replies with raw (indexed) record data; which can then be used to fill in the fields.

Or, if your recordset is always going to be quite small; you could use JSP to write the records into Javascript arrays; and then move through them when 'next' is clicked.

I think, you may get better assistance at the JSP forum. Personally, I have no way to run JSP code; so I can't give you particularly specific advice.

Dear Matt,
thank u for your advice.
i hv also posted the forum in jsp.
as i m learning it myself was a bit difficult to understand u.
still thanks

Hey, if you are using Java/JSP and/or servlets you can always save your rs object in the session, which would make it remain accross browser transactions...BUT I have never tried it that way...

I also NEVER work with MS Access unless it is on my desktop...it is just not a good choice even for learning...despite what the book might have told you... PostgreSQL or MySQL are free and VERY simple to download and install/setup if you follow the instructions, in the old days they were more difficult, but today they are a breeze... use them...

I have Apache Web Server, Apache Tomcat and PostgreSQL installed on my Windows XP laptop and use them for dev testing and POC (proof of concept) creation all the time...it is a better learning environment, so I suggest you invest 2 hours and set them all up...they can all be done in 2 hours total or less usually...

You should have an "order by" in your SQL to ensure the order is always the same... then use a limit and offset to depending on the DB support, some accept "limit 10, 20" for ten at a time starting from record #20... others use 2 separate keywords "limit 10 offset 20" ... once you know which way works for you DB, you can set limit 1 and offset iNum where "iNum" is the record number to show...

you set input field in the page to have the current value (or next value) and use those to figure out what the offset should be next time around...

i.e.
<code>


<input type="hidden" name="next" value="<%=iNum%>">

</code>

you could extend this then to provide forward and back or even jump capability for your records, but you would be reselecting the record each time, so you must be sure they are properly ordered with the "order by" keywords

first.i want to know if your problem was solved.
if yes.please tell me how you did it..

My problem is..i want to do something similar, but what i want is when NEXT button is clicked,i want the old record to disappear and the new record be displayed at the same exact place..

can anyone help please?? :)

first.i want to know if your problem was solved.
if yes.please tell me how you did it..

My problem is..i want to do something similar, but what i want is when NEXT button is clicked,i want the old record to disappear and the new record be displayed at the same exact place..

can anyone help please?? :)

Hello Sharma,
I am with the same problem as you asked, did you find the solution? can you help me.
I am programming with jsp, mysql and running tomcat

This article has been dead for over six months. Start a new discussion instead.