jsp页面连接数据库只显示一条记录?
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();Stringu...
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver")
.newInstance();
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";
String user1 = "sa";
String password1 = "000";
java.sql.Connection conn = null;
Statement stmt = null;
String sql = "select * from subject";
conn = DriverManager.getConnection(url, user1, password1);
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
out.print(rs.getInt("id") + ".");
out.println(rs.getString("subname"));
}
rs.close();
stmt.close();
conn.close();
%>
结果只显示数据库中的第一条记录 展开
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver")
.newInstance();
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";
String user1 = "sa";
String password1 = "000";
java.sql.Connection conn = null;
Statement stmt = null;
String sql = "select * from subject";
conn = DriverManager.getConnection(url, user1, password1);
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
out.print(rs.getInt("id") + ".");
out.println(rs.getString("subname"));
}
rs.close();
stmt.close();
conn.close();
%>
结果只显示数据库中的第一条记录 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询