请告诉我这是什么问题。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
</body>
<form method="post">
<table border="2">
<tr>
<td>ID</td>
<td>NAME</td>
<td>SKILL</td>
<td>ACTION</td>
</tr>
<%
try
{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost/test";
String username="root";
String password="root";
String query="select * from jsp1";
Connection conn=DriverManager.getConnection(url,username,password);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
%>
<tr><td><%rs.getInt("ID"); %></td></tr>
<tr><td><%rs.getString("NAME"); %></td></tr>
<tr><td><%rs.getString("SKILL"); %></td></tr>
<%
}
%>
</table>
<%
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</form>
</html>
答案 0 :(得分:12)
这里的问题非常简单。如果要在JSP中显示值,则必须使用&lt;%=%&gt;标记而不是&lt; %%&gt;,这是已解决的代码:
<tr>
<td><%=rs.getInt("ID") %></td>
<td><%=rs.getString("NAME") %></td>
<td><%=rs.getString("SKILL") %></td>
</tr>
答案 1 :(得分:1)
您还可以将数据打印到HTML / JSP文档上。 像:-
<!DOCTYPE html>
<html>
<head>
<title>Jsp Sample</title>
<%@page import="java.sql.*;"%>
</head>
<body bgcolor=yellow>
<%
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=(Connection)DriverManager.getConnection(
"jdbc:mysql://localhost:3306/forum","root","1234");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from student;");
%><table border=1 align=center style="text-align: center">
<%while(rs.next())
{
%>
<tr>
<td><%out.print(rs.getString(1));%></td>
<td><%out.print(rs.getString(2));%></td>
<td><%out.print(rs.getString(3));%></td>
<td><%out.print(rs.getString(4));%></td>
<td><%out.print(rs.getString(5));%></td>
<td><%out.print(rs.getString(6));%></td>
<td><%out.print(rs.getString(7));%></td>
</tr>
<%
}%>
</table><br>
<%}
catch(SQLException e){
out.print(e.getMessage());%><br><%
}
%>
</body>
</html>
<!--executeUpdate() mainupulation and executeQuery() for retriving-->
答案 2 :(得分:0)
MONEY/DECIMAL