2017-08-08 62 views

回答

1

嗯这是一个非常愚蠢的问题,但既然你问了,所以我在这里写答案。

您可以使用JDBC从数据库中获取数据,然后使用响应printwriter来显示它。

示例程序

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>); 

} 

所以,现在运行的servlet和结果将在浏览器上显示出来。

相关问题