-4

How to display data in the HTML page from the Database using Servlet ?

1 Answers1

0

Well It's a very silly question but since you have asked so I am writing answer here.

You can fetch the Data from the Database using JDBC and then use response printwriter to display it.

Sample Program

Connection con;
PrintWriter out = response.getWriter();
response.setContentType("text/html");
con = DriverManager.getConnection("jdbc:mysql://localhost:" + "3306" + "/" + "pinnnacledb1", "root", "");
String query = "Select * from table where something = ?";
PreparedStatement pst = currentCon.prepareStatement(query);
pst.setString(1, username);
ResultSet rs = pst.executeQuery();
while (rs.next())
{
    //Your logic for display
    out.println(<html>Whole html logic can be written here</html>);

}

So now run the servlet and result will be displayed on the browser.

Chetan Kumar
  • 1,331
  • 1
  • 10
  • 16