大家看看为什么我的连接mysql的jsp文件运行起来什么都不显示呀!
我想通过这个程序把数据库Testdb 中的Student表的全部内容打印出来,但是运行结果是什么都没有,不知道怎么回事儿,知道的告诉一声啊会加分的。--------------------编程问答-------------------- 驱动有没?库连上没?库里有数据没?报的什么错误? --------------------编程问答-------------------- statement.executeQuery("select id,name,score from 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>
这条语句,应该是
rSet = statement.executeQuery("select id,name,score from Student");
吧 ??
--------------------编程问答--------------------
String url = "jdbc:mysql://localhost/Testdb";
localhost后面是否要加端口号呢? --------------------编程问答--------------------
还有rSet初始化为null之后没有赋值。
应该是:
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>
补充:Java , Java EE