User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 329,220 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,260 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 3736 | Replies: 3
Reply
Join Date: Mar 2007
Location: India
Posts: 28
Reputation: bhuvan83 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bhuvan83's Avatar
bhuvan83 bhuvan83 is offline Offline
Light Poster

how to get to next record on click of a button.

  #1  
Mar 13th, 2007
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>
Last edited by bhuvan83 : Mar 13th, 2007 at 12:30 am.
Bhuvan Aggarwal
There is no word impossible.
its i m possible
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Location: Deptford, London
Posts: 899
Reputation: MattEvans will become famous soon enough MattEvans will become famous soon enough 
Rep Power: 4
Solved Threads: 43
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is online now Online
Practically a Posting Shark

Re: how to get to next record on click of a button.

  #2  
Mar 13th, 2007
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.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
Join Date: Mar 2007
Location: India
Posts: 28
Reputation: bhuvan83 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bhuvan83's Avatar
bhuvan83 bhuvan83 is offline Offline
Light Poster

Re: how to get to next record on click of a button.

  #3  
Mar 13th, 2007
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
Bhuvan Aggarwal
There is no word impossible.
its i m possible
Reply With Quote  
Join Date: Mar 2007
Posts: 83
Reputation: rgtaylor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
rgtaylor rgtaylor is offline Offline
Junior Poster in Training

Re: how to get to next record on click of a button.

  #4  
Mar 23rd, 2007
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Marketplace (Sponsored Links)
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 10:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC