我想通过这个程序把数据库Testdb 中的Student表的全部内容打印出来,但是运行结果是什么都没有,不知道怎么回事儿,知道的告诉一声啊会加分的。 <%@ page contentType="text/html;charset=GB2312"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DriverManager"%>
<html>
<head>
<title>show.jsp</title>
</head>
<body bgcolor="grey">
<table border="1">
<%
Connection connection = null;
%>
<%
try{
ResultSet rSet = null;
String url = "jdbc:mysql://localhost/Testdb";
String user = "root";
String password = "root";
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(url, user, password);
Statement statement = connection.createStatement();
statement = connection.createStatement();
statement.executeQuery("select id,name,score from Student");
out.println("<table boreder=1 width=400>");
while(rSet.next())
{
%>
<tr>
<td> <%=rSet.getInt("name")%> </td>
<td> <%=rSet.getString("name")%> </td>
<td> <%=rSet.getFloat("name")%> </td>
</tr>
<%
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (connection.isClosed()) {
connection.close();
}
}
catch (Exception e2) {
e2.printStackTrace();
}
}
%>
</body>
</html>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DriverManager"%>
<html>
<head>
<title>show.jsp</title>
</head>
<body bgcolor="grey">
<table border="1">
<%
Connection connection = null;
%>
<%
try{
ResultSet rSet = null;
String url = "jdbc:mysql://localhost/Testdb";
String user = "root";
String password = "root";
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(url, user, password);
Statement statement = connection.createStatement();
statement = connection.createStatement();
statement.executeQuery("select id,name,score from Student");
out.println("<table boreder=1 width=400>");
while(rSet.next())
{
%>
<tr>
<td> <%=rSet.getInt("name")%> </td>
<td> <%=rSet.getString("name")%> </td>
<td> <%=rSet.getFloat("name")%> </td>
</tr>
<%
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (connection.isClosed()) {
connection.close();
}
}
catch (Exception e2) {
e2.printStackTrace();
}
}
%>
</body>
</html>
解决方案 »
- java的jdk-6u34-windows-i586和eclipse安装问题
- HTTP Status 404 - There is no Action mapped for namespace / and action name hell
- 一个关于web工程导入自己写的jar档问题
- struts资源文件
- ejb调数据库连接池的问题
- Connection reset by peer:socket write error
- new org.apache.struts.action.ActionMessage(key,value)中的value有什么用?
- Struts问题:Attribute name invalid for tag form according to TLD
- 超级简单,小弟郁闷死了?
- 一个关于编译Struts架构程序的入门级问题
- 这是我做的求完数的代码 我是在不知道哪错了
- hibernate save 自动提交,但是delete,update却不行,求解惑!
这条语句,应该是
rSet = statement.executeQuery("select id,name,score from Student");
吧 ??
localhost后面是否要加端口号呢?
应该是:
rSet = statement.executeQuery("select id,name,score from Student");
确实
rSet = statement.executeQuery("select id,name,score from Student");我的
<td> <%=rSet.getInt("name")%> </td>
<td> <%=rSet.getString("name")%> </td>
<td> <%=rSet.getFloat("name")%> </td>应该改为 <td> <%=rSet.getInt("id")%> </td>
<td> <%=rSet.getString("name")%> </td>
<td> <%=rSet.getFloat("score")%> </td>