【发布时间】:2018-04-04 18:36:09
【问题描述】:
如何重写下面的代码以直接在我的网页上而不是在控制台上打印结果?
public static void doSQL() {
try {
String url = "jdbc:msql://...";
Connection conn = DriverManager.getConnection(url,"user","password");
Statement stmt = conn.createStatement();
ResultSet rs;
rs = stmt.executeQuery("SELECT Lname FROM Customers WHERE Snum = 2001");
while ( rs.next() ) {
// I want to print the ResultSet directly on my HTML page, how may I go about doing that?
String lastName = rs.getString("Lname");
System.out.println(lastName);
}
conn.close();
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
【问题讨论】:
-
那么您使用的是哪些网络技术?如果您使用的是 JSP,您可以在页面上打印一个表格。
-
没有 JSP,只有普通的 servlet。
-
如果我只是用 Print Writer 打印结果集,结果只是一个带有一堆随机字母和数字的对象名称。
标签: java html mysql database resultset