944,196 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Marked Solved
  • Views: 7881
  • JSP RSS
Mar 13th, 2007
0

how to get to next record on click of a button

Expand Post »
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->


JSP Syntax (Toggle Plain Text)
  1. <%@ page import="java.sql.*" %>
  2. <htmL>
  3. <%
  4. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  5. String dataSourceName="mydsn";
  6. String dbURL="jdbc:odbc:" + dataSourceName;
  7. Connection con= DriverManager.getConnection(dbURL,"","");
  8. Statement s=con.createStatement();
  9. s.execute("select * from web");
  10. ResultSet rs;
  11. rs=s.getResultSet() ;
  12. rs.next();
  13. %>
  14. <body>
  15. <script>
  16. function getDetails()
  17. {
  18. rs.next()
  19. }
  20. </script>
  21. <form method="post">
  22. Website:<input type="text" value="<%=rs.getString(1) %>"><br>
  23. <a rel="nofollow" href="http://www.daniweb.com/techtalkforums/<input" target="_blank">Url:<input</a> type="text" value="<%=rs.getString(2) %>"><br>
  24. Category: <input type="text" value="<%=rs.getString(3) %>"><br>
  25. Description: <input type="text" value="<%=rs.getString(4) %>"><br>
  26. Search Engine-><br>
  27. Yahoo: <input type="text" value="<%=rs.getString(5) %>"><br>
  28. Google: <input type="text" value="<%=rs.getString(6) %>"><br>
  29. Altavista: <input type="text" value="<%=rs.getString(7) %>"><br>
  30. <input type="button" value="Next" onClick="getDetails()">
  31. </form>
  32. </body>
  33. </html>
Last edited by bhuvan83; Mar 13th, 2007 at 7:53 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
bhuvan83 is offline Offline
29 posts
since Mar 2007
Mar 14th, 2007
0

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

Why don't you store whole databse into bean and then on button press request next set
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 875
Code tags enforcer
peter_budo is offline Offline
6,659 posts
since Dec 2004
Mar 14th, 2007
0

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

bro thanks for ur reply.
but i dont know how to use beans.
can u show me a small code????
Last edited by bhuvan83; Mar 14th, 2007 at 6:14 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
bhuvan83 is offline Offline
29 posts
since Mar 2007
Mar 15th, 2007
0

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

nice explanation on wikipedia

bellow is how do I get data from my db about events in calendar
JSP Syntax (Toggle Plain Text)
  1. CalendarData[] eArr = new CalendarData[exists];
  2. try
  3. {
  4. int i=0;
  5. strQuery = "select event_type, ev_date, ev_time, ev_description from calendar_events where userName='" + strUser + "' and cal_id='" + calId + "'";
  6. rs = stmt.executeQuery( strQuery);
  7. while( rs.next())
  8. {
  9. eArr[i] = new CalendarData();
  10. eArr[i].setEventType(rs.getString("event_type") );
  11. eArr[i].setEventDate(rs.getString("ev_date") );
  12. eArr[i].setEventTime(rs.getInt("ev_time") );
  13. eArr[i].setEventDescription(rs.getString("ev_description") );
  14. i++;
  15. } // end while loop
  16. session.setAttribute("eventArray", eArr);
  17. CalendarData[] test = (CalendarData[]) session.getAttribute("eventArray");

Also do not connect to DB from JSP use servlets
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 875
Code tags enforcer
peter_budo is offline Offline
6,659 posts
since Dec 2004
Mar 16th, 2007
0

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

thanks got the soln
Reputation Points: 10
Solved Threads: 0
Light Poster
bhuvan83 is offline Offline
29 posts
since Mar 2007
Sep 19th, 2011
0
Re: how to get to next record on click of a button
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 :-)
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
sagar_danceking is offline Offline
56 posts
since Jul 2011

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: How to hide url in jsp ?
Next Thread in JSP Forum Timeline: Redirect to a page with parameters





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC