Html 从oracle 10g检索多行
我已经在oracle中创建了一个表,其中包括每个学院的学院名、学生名、注册号和结果,它们属于每个学院的特定学院和学院ID,以及数据存储的日期 现在我想给大学id和日期,我想让所有学生的名字和他们的结果和regno在一个类似表格的结构在浏览器中我已经写了一个html页面给大学id和日期和一个jsp页面检索不同的领域从数据库,但它不工作..这是我的代码为这两个网页 这是我的html页面Html 从oracle 10g检索多行,html,jsp,oracle10g,Html,Jsp,Oracle10g,我已经在oracle中创建了一个表,其中包括每个学院的学院名、学生名、注册号和结果,它们属于每个学院的特定学院和学院ID,以及数据存储的日期 现在我想给大学id和日期,我想让所有学生的名字和他们的结果和regno在一个类似表格的结构在浏览器中我已经写了一个html页面给大学id和日期和一个jsp页面检索不同的领域从数据库,但它不工作..这是我的代码为这两个网页 这是我的html页面 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitio
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org /TR/html4/loose.dtd">
<html>
<head>
<script>
function check()
{
var a=result.college_id.value;
var b=result.date.value;
if(a==""|| b=="")
{
alert("fill the fields")
}
else
{
result.action="result.jsp";
result.method="post";
result.submit();
}
}
</script>
</head>
<body bgcolor="#cc99ff">
<form name="result">
<center>
<table>
<tr>
<td>college_id:</td>
<td><input type="text" name="college_id"></td>
</tr>
<tr>
<td>date:</td>
<td><input type="text" name="date"></td>
</tr>
<tr>
<td>
<input type="Button" value="Submit" onClick="check()">
</td>
</tr>
</table>
</center>
</body>
</html>
函数检查()
{
var a=结果、学院id、价值;
var b=结果.date.value;
如果(a==“”| b==“”)
{
警报(“填写字段”)
}
其他的
{
result.action=“result.jsp”;
result.method=“post”;
结果。提交();
}
}
学院编号:
日期:
现在这是我的jsp页面,用于检索多行
<html>
<body background="main_BG.jpg">
<%@page language="java"%>
<%@page import="java.sql.*,java.util.*"%>
<%!
Connection con;
PreparedStatement ps;
ResultSet rs;
String college_id;
String college_name;
String regno;
String student_name;
String result;
String date;
%>
<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","pro","pro
");
college_id=request.getParameter("college_id");
date=request.getParameter("date");
ps=con.prepareStatement("select * from add_result where college_id=? and date=?");
ps.setString(1,college_id);
ps.setString(6,date);
rs=ps.executeQuery();
while(rs.next())
{
college_name=rs.getString(2);
regno=rs.getString(3);
student_name=rs.getString(4);
result=rs.getString(5);
}
else
{
out.println("no data found");
}
}
catch(Exception e)
{
out.println("<center><b><font color=lightblue>some error occured...please try again</font></b></center>");
out.println("<br><br><a href='result.html'><center><b><font color=lightblue>click here to return..</font></b></center>");
}
%>
<center>
<font color=lightblue>
<b>
Information of student with college_id [<%=college_id%>]:
</b>
</font>
</center>
<p style="position:absolute;left:100;top:100">
<table border="2" width="100%">
<th style="color:yellow">
college_name
</th>
<th style="color:yellow">
regno
</th>
<th style="color:yellow">
student_name
</th>
<th style="color:yellow">
result
</th>
<tr>
<td style="color:lightgreen" align="center"><%=college_name%></td>
<td style="color:lightgreen" align="center"><%=regno%></td>
<td style="color:lightgreen" align="center"><%=student_name%></td>
<td style="color:lightgreen" align="center"><%=result%></td>
</tr>
</table>
</p>
</body>
</html>
学院id为[]的学生信息:
学院名称
雷格诺
学生姓名
结果
学院id为[]的学生信息:
学院名称
雷格诺
学生姓名
结果
没有找到任何数据
您能详细介绍一下“不工作”吗?你有错误吗?如果是,错误是什么?数据是否未以您期望的格式显示?如果是这样的话,你能描述一下你看到了什么和你想看到什么吗?没有错误,但数据没有显示,而不是在所有字段下面显示空数据。你得到一个包含多行的HTML表格,但所有数据都是空的?或者您是说该表丢失了吗?表在那里,但所有数据仍然为空。表显示为空值,并且您的if and while条件显示在表上方。我已经完成了该操作,当我们只有一行,但没有处理多行时。我已经编辑了答案以打印sql控制台。但现在我怀疑date
列的数据类型。那是什么。我们从这里传递字符串,我有两行,college_id=1,date=20-apr-12日期列的数据类型是date
<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","pro","pro ");
college_id=request.getParameter("college_id");
date=request.getParameter("date");
String sql = "select * from add_result where college_id=? and date=?";
ps=con.prepareStatement(sql);
ps.setString(1,college_id);
//ps.setString(6,date);
ps.setString(2,date);
System.out.println("Sql: " + sql);
rs=ps.executeQuery();
// process resultset below
}
catch(Exception e)
{
out.println("<center><b><font color=lightblue>some error occured...please try again</font></b></center>");
out.println("<br><br><a href='result.html'><center><b><font color=lightblue>click here to return..</font></b></center>");
}
%>
<center>
<font color=lightblue>
<b>
Information of student with college_id [<%=college_id%>]:
</b>
</font>
</center>
<p style="position:absolute;left:100;top:100">
<table border="2" width="100%">
<th style="color:yellow">
college_name
</th>
<th style="color:yellow">
regno
</th>
<th style="color:yellow">
student_name
</th>
<th style="color:yellow">
result
</th>
<%
if(rs!=null){
while(rs.next())
{
college_name=rs.getString(2);
regno=rs.getString(3);
student_name=rs.getString(4);
result=rs.getString(5);
%>
<tr>
<td style="color:lightgreen" align="center"><%=college_name%></td>
<td style="color:lightgreen" align="center"><%=regno%></td>
<td style="color:lightgreen" align="center"><%=student_name%></td>
<td style="color:lightgreen" align="center"><%=result%></td>
</tr>
<%
} // result set loop ends here
}else{
%>
<tr>
<td colspan="4" style="color:red" align="center">No Data Found</td>
</tr>
<%
} //if condition ends here
%>