I am trying to display my user table on to a table in my JSP page. But the data is not shown when I run the JSP page.
I have a mySQL schema called "eyetracker" and a table called "user". Appreciate your help.. If possible , I want to retrieve mySQL data by using servlet and display it in a JSP page...
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<form method="post">
<table border="2">
<tr>
<td>user ID</td>
<td>Birthday</td>
<td>Gender</td>
<td>First Name</td>
<td>Last Name</td>
</tr>
<%
try
{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/eyetracker";
String username="root";
String password="root";
String query="select * from eyetracker";
Connection conn=DriverManager.getConnection(url, username, password);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
%>
<tr><td><%rs.getInt("userID"); %></td></tr>
<tr><td><%rs.getDate("dob"); %></td></tr>
<tr><td><%rs.getString("gender"); %></td></tr>
<tr><td><%rs.getString("firstName"); %></td></tr>
<tr><td><%rs.getString("lastName"); %></td></tr>
<%
}
%>
</table>
<%
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</form>`
update your small code like following,
%>
<tr><td><%out.println(rs.getInt("userID")); %></td></tr>
<tr><td><%out.println(rs.getDate("dob")); %></td></tr>
<tr><td><%out.println(rs.getString("gender")); %></td></tr>
<tr><td><%out.println(rs.getString("firstName")); %></td></tr>
<tr><td><%out.println(rs.getString("lastName")); %></td></tr>
<tr><td><%=rs.getInt("userID"); %></td></tr>
<tr><td><%=rs.getDate("dob"); %></td></tr>
<tr><td><%=rs.getString("gender"); %></td></tr>
<tr><td><%=rs.getString("firstName"); %></td></tr>
<tr><td><%=rs.getString("lastName"); %></td></tr>
<%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With