evergreean43
Technical User
Earlier this week I posted a JSP Bean that showed null result. I got it working to now it will show a database value but now I want it to show all the records.
In the \Tomcat 5.5\logs it shows all the records but the JSP displays only 1 record which seems to be the last record value.
Please advise what I am doing wrong.
JSP:
Java class file:
Output from JSP is:
Jones
The \Tomcat 5.5\logs output shows all the records which is what I want the JSP to show:
Edwardson
Smith
Carson
Jones
In the \Tomcat 5.5\logs it shows all the records but the JSP displays only 1 record which seems to be the last record value.
Please advise what I am doing wrong.
JSP:
Code:
<jsp:useBean id="tester" class="colors.Tester"/>
<jsp:setProperty name="tester" property="lastName" value="*" />
<jsp:getProperty name="tester" property="lastName" />
Java class file:
Code:
package colors;
import java.io.*;
import java.sql.*;
import java.util.*;
public class Tester
{
protected String lastName;
String mquery = "";
public Tester(){}
public String getLastName()
{
this.viewDatabaseTable();
return lastName;
}
public void setLastName(String aLastName)
{
lastName = aLastName;
}
public void viewDatabaseTable()
{
exeQry(mquery);
}
public void exeQry(String mquery)
{
try
{
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/myfirst?user=root&password=aaaaaa");
Statement stmt = conn.createStatement();
ResultSet results = stmt.executeQuery("SELECT * from user");
while(results.next())
{
lastName = results.getString("lastName");
System.out.println(lastName);
}
}
catch(Exception e)
{
System.out.println("Exception here.");
}
}
}
Output from JSP is:
Jones
The \Tomcat 5.5\logs output shows all the records which is what I want the JSP to show:
Edwardson
Smith
Carson
Jones