Data Access Objects in jsp and beans?

Reply

Join Date: Oct 2008
Posts: 1
Reputation: paul_1234 is an unknown quantity at this point 
Solved Threads: 0
paul_1234 paul_1234 is offline Offline
Newbie Poster

Data Access Objects in jsp and beans?

 
0
  #1
Oct 27th, 2008
Hi, I'm currently working on concerning a student record with guardians/parents... im using the java ee framework.. I'm having problems on retrieving the data on our database(MySQL).. Here is what i did.. i have created a class to retrieve those data from the database..
my problem is that whenever i retrieve that data in my jsp page, it only shows this Ljava.lang.String@123EGa something similar to this..

CLASS PLARENTS ..
  1. package com;
  2. //this class is the one that i used to retrieve the data..
  3. import java.io.*;
  4. import java.sql.*;
  5. import javax.servlet.jsp.*;
  6. import javax.servlet.jsp.tagext.*;
  7.  
  8. public class Parents {
  9.  
  10. public String[] lastname;
  11. public String[] firstname;
  12. public String[] middlename;
  13. public String[] relation;
  14.  
  15. private Connection connection = null;
  16. private Statement statement = null;
  17. private ResultSet rs = null;
  18. Connect con = new Connect();
  19. int count = 0;
  20.  
  21. public Parents(){}
  22.  
  23. public Parents(int idno) {
  24. int i = 0;
  25. try {
  26. Class.forName("com.mysql.jdbc.Driver").newInstance();
  27. connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sis",con.user,con.password);
  28. statement = connection.createStatement();
  29. rs = statement.executeQuery("SELECT * FROM guardians WHERE studidno='" + idno + "'");
  30.  
  31. if (rs.last()) {
  32. count = rs.getRow();
  33. }
  34.  
  35. lastname = new String[count];
  36. firstname = new String[count];
  37. middlename = new String[count];
  38. relation = new String[count];
  39.  
  40. while (rs.next()){
  41. lastname[i] = rs.getString("lastname");
  42. firstname[i] = rs.getString("firstname");
  43. middlename[i] = rs.getString("middlename");
  44. relation[i] = rs.getString("relation");
  45. i++;
  46. }
  47.  
  48. } catch (Exception e) {
  49. e.printStackTrace();
  50. }
  51. }
  52.  
  53. //setters in here..
  54.  
  55. public String[] getLastname(){return lastname;}
  56.  
  57. public String[] getFirstname () {return firstname;}
  58.  
  59. public String[] getMiddlename () {return middlename;}
  60.  
  61. public String[] getRelation () {return relation;}
  62.  
  63. }
  64.  
  65. and this is what i placed in my jsp page..
  66. <%
  67. Parents p = new Parents(info.getIdno());
  68. for (int i = 0; i < p.getFirstname().length; i++ ) {
  69. %>
  70.  
  71.  
  72. <%= p.getLastname() %>
  73.  
  74. Relationship:
  75.  
  76. <%= p.getFirstname() %>
"according to what i have read on some searches, the best way to do it is by using data access objects..".. can anybody just an idea on how to do this using data access objects or give some sample codes for me to do this.. Im asking for an idea.. or any sample codes will do.. i have been working on this for about 2 days now, I've done so many researches and i haven't quite find any answer to my problem..
Last edited by ~s.o.s~; Oct 28th, 2008 at 1:50 am. Reason: Added code tags, learn to use them.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,651
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Data Access Objects in jsp and beans?

 
1
  #2
Oct 28th, 2008
Don't use scriptlets; use JSP's only for view purposes. Use JSTL along with servlet.

> whenever i retrieve that data in my jsp page, it only shows this
> Ljava.lang.String@123EGa something similar to this..

This is because you are trying to print a String array and the above just happens to how toString of an array looks like.

Here you can find some sample J2EE applications along with the J2EE design patterns free book which you can use to read more about Data Access Object pattern.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JSP Forum


Views: 916 | Replies: 1
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC