Hi friend,
Code to help in solving the problem :
"view1.jsp"
<%@page import="java.sql.*"%>
<%
Connection conn = null;
String url = "jdbc:
mysql://192.168.10.112:3306/";;;
String dbName = "student";
String driver = "com.mysql.jdbc.Driver";
String username = "root";
String userPassword = "root";
String color = "#F9EBB3";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,username,userPassword);
Statement st = conn.createStatement();
String strQuery = "select * from rollno";
ResultSet rs = st.executeQuery(strQuery);
int count=0;
%> <br><br><br>
<table width="700px" align="center" style="border:1px solid #000000;" >
<tr>
<td colspan=8 align="center" style="background-color:ffeeff"><b>All Students</b></td>
</tr>
<tr style="background-color:efefef;">
<td><b>Id</b></td>
<td><b>Roll_no</b></td>
<td><b>LastName</b></td>
</tr>
<%
while(rs.next()){
if((count%2)==0){
color = "#eeffee";
}else{
color = "#F9EBB3";
}
count++;
%> <tr style="background-color:<%=color%>;">
<td><a href='view2.jsp?id=<%=rs.getInt("id")%>'><%=rs.getInt("id")%></a></td>
<td><%=rs.getString("roll_no")%></td>
<td><%=rs.getString("lastname")%></td>
</tr>
<%
}
%>
</table>
<br><br>
<table width="100px" align="center" border=0><tr>
<% conn.close();
} catch (Exception e) {
e.printStackTrace();
}
%>
</tr>
</table>
</body>
</html>
Id having an anchor link .You click on it and display the full details on the next page "view2.jsp"
"view2.jsp"
<%@page import="java.sql.*"%>
<%
Connection conn = null;
String url = "jdbc:
mysql://192.168.10.112:3306/";;;
String dbName = "student";
String driver = "com.mysql.jdbc.Driver";
String username = "root";
String userPassword = "root";
String color = "#F9EBB3";
int id=0;
String roll_no="";
String lastname="";
if(request.getParameter("id")!=null)
{
id = Integer.parseInt(request.getParameter("id").toString());
}
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,username,userPassword);
Statement st = conn.createStatement();
String strQuery = "select * from rollno where id="+id;
ResultSet rs = st.executeQuery(strQuery);
int count=0;
if(rs.next()){
roll_no=rs.getString("roll_no");
lastname=rs.getString("lastname");
}
%> <br><br><br>
<table width="200px" align="center" style="border:1px solid #000000;" >
<tr><td width="50px"></td><td width="10px"></td><td></td></tr>
<tr style="background-color:efefef;">
<tr><td><b>Id</b></td><td align="center"><b>:</b></td><td><%=id%></tr>
<tr><td><b>Roll_no</b></td><td align="center"><b>:</b></td><td><%=roll_no%></tr>
<tr><td><b>LastName</b></td><td align="center"><b>:</b></td><td><%=lastname%></tr>
</table>
<br><br>
<table width="100px" align="center" border=0><tr>
<% conn.close();
} catch (Exception e) {
e.printStackTrace();
}
%>
</tr>
</table>
</body>
</html>
Thanks