JSP页面在获取表单输入的数据后怎么显示Mysql数据库几张表中相应的数据?拜托大神帮帮忙代码如下
我调试了很多次,硬是没弄对。。麻烦大神帮忙看一下啦~不胜感激!代码如下:<%@pagelanguage="java"contentType="text/html;char...
我调试了很多次,硬是没弄对。。麻烦大神帮忙看一下啦~不胜感激!
代码如下:
<%@ page language="java" contentType="text/html;charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<html>
<body>
<%
Connection conn=null;
try
{
String ss1=request.getParameter("num1");
String ss2=request.getParameter("num2");
String ss3=request.getParameter("num3");
String ss4=request.getParameter("num4");
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test1","root","1234");
Statement stmt1=conn.createStatement();
Statement stmt2=conn.createStatement();
Statement stmt3=conn.createStatement();
Statement stmt4=conn.createStatement();
String query1="select content from table1 where num='ss1'";
String query2="select content from table2 where num='ss2'";
String query3="select content from table3 where num='ss3'";
String query4="select content from table4 where num='ss4'";
ResultSet rs1=stmt1.executeQuery(query1);
while(rs1.next())
{
String s1=rs1.getString("content");
out.print(s1);
}
ResultSet rs2=stmt2.executeQuery(query2);
while(rs2.next())
{
String s2=rs2.getString("content");
out.print(s2);
}
ResultSet rs3=stmt3.executeQuery(query3);
while(rs3.next())
{
String s3=rs3.getString("content");
out.print(s3);
}
ResultSet rs4=stmt4.executeQuery(query4);
while(rs4.next())
{
String s4=rs4.getString("content");
out.print(s4);
}
rs1.close();
stmt1.close();
rs2.close();
stmt2.close();
rs3.close();
stmt3.close();
rs4.close();
stmt4.close();
conn.close();
}
catch(Exception e)
{
out.println(e.getMessage());
}
%>
</body>
</html> 展开
代码如下:
<%@ page language="java" contentType="text/html;charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<html>
<body>
<%
Connection conn=null;
try
{
String ss1=request.getParameter("num1");
String ss2=request.getParameter("num2");
String ss3=request.getParameter("num3");
String ss4=request.getParameter("num4");
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test1","root","1234");
Statement stmt1=conn.createStatement();
Statement stmt2=conn.createStatement();
Statement stmt3=conn.createStatement();
Statement stmt4=conn.createStatement();
String query1="select content from table1 where num='ss1'";
String query2="select content from table2 where num='ss2'";
String query3="select content from table3 where num='ss3'";
String query4="select content from table4 where num='ss4'";
ResultSet rs1=stmt1.executeQuery(query1);
while(rs1.next())
{
String s1=rs1.getString("content");
out.print(s1);
}
ResultSet rs2=stmt2.executeQuery(query2);
while(rs2.next())
{
String s2=rs2.getString("content");
out.print(s2);
}
ResultSet rs3=stmt3.executeQuery(query3);
while(rs3.next())
{
String s3=rs3.getString("content");
out.print(s3);
}
ResultSet rs4=stmt4.executeQuery(query4);
while(rs4.next())
{
String s4=rs4.getString("content");
out.print(s4);
}
rs1.close();
stmt1.close();
rs2.close();
stmt2.close();
rs3.close();
stmt3.close();
rs4.close();
stmt4.close();
conn.close();
}
catch(Exception e)
{
out.println(e.getMessage());
}
%>
</body>
</html> 展开
1个回答
推荐于2016-03-12
展开全部
每张表对应一个vo (表里的字段可以在这个类里面找到对应的变量)
查出来的结果集封装到voList ,
用标签或者<%%> 迭代出来
<%--jsp scriptlet --%>
<table border="1">
<tr>
<td>列1</td>
<td>列2</td>
</tr>
<%
while (rs.next()) {
%>
<tr>
<td><%=rs.getString()%></td>
<td><%=rs.getString()%></td>
</tr>
<%
}
%>
</table>
查出来的结果集封装到voList ,
用标签或者<%%> 迭代出来
<%--jsp scriptlet --%>
<table border="1">
<tr>
<td>列1</td>
<td>列2</td>
</tr>
<%
while (rs.next()) {
%>
<tr>
<td><%=rs.getString()%></td>
<td><%=rs.getString()%></td>
</tr>
<%
}
%>
</table>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询