| | |
Data Access Objects in jsp and beans?
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2008
Posts: 1
Reputation:
Solved Threads: 0
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 ..
"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..
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 ..
JSP Syntax (Toggle Plain Text)
package com; //this class is the one that i used to retrieve the data.. import java.io.*; import java.sql.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; public class Parents { public String[] lastname; public String[] firstname; public String[] middlename; public String[] relation; private Connection connection = null; private Statement statement = null; private ResultSet rs = null; Connect con = new Connect(); int count = 0; public Parents(){} public Parents(int idno) { int i = 0; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sis",con.user,con.password); statement = connection.createStatement(); rs = statement.executeQuery("SELECT * FROM guardians WHERE studidno='" + idno + "'"); if (rs.last()) { count = rs.getRow(); } lastname = new String[count]; firstname = new String[count]; middlename = new String[count]; relation = new String[count]; while (rs.next()){ lastname[i] = rs.getString("lastname"); firstname[i] = rs.getString("firstname"); middlename[i] = rs.getString("middlename"); relation[i] = rs.getString("relation"); i++; } } catch (Exception e) { e.printStackTrace(); } } //setters in here.. public String[] getLastname(){return lastname;} public String[] getFirstname () {return firstname;} public String[] getMiddlename () {return middlename;} public String[] getRelation () {return relation;} } and this is what i placed in my jsp page.. <% Parents p = new Parents(info.getIdno()); for (int i = 0; i < p.getFirstname().length; i++ ) { %> <%= p.getLastname() %> Relationship: <%= p.getFirstname() %>
Last edited by ~s.o.s~; Oct 28th, 2008 at 1:50 am. Reason: Added code tags, learn to use them.
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
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.
> 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
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
![]() |
Similar Threads
- struts tutorials (Java)
- Help for learnign JSP (JSP)
- Java Tutorials (Java)
Other Threads in the JSP Forum
- Previous Thread: Help with Javabean
- Next Thread: java web development urgent 1month to go!!
Views: 916 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for JSP
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient project read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write






