2012-04-23 107 views
-1

多行的我創建Oracle中的表,包括college_names,student_name,REGNO並導致屬於特定的大學,每個college_ids和其上的數據已被存儲各高校和日期...Retreival從Oracle 10g中

現在我想給college_id和日期,我希望所有學生的名字都與他們的結果和regno在瀏覽器中的表結構類似我已經寫了一個html頁面給予college_id和日期和一個jsp頁面來檢索不同的頁面從數據庫字段,但它不工作..這裏是我的兩個頁面的代碼..

這是我的html頁面

<!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> 

現在,這裏是我的檢索多行的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> 
+0

你能在 「不工作」 展開?你有錯誤嗎?如果是這樣,有什麼錯誤?數據是否不以您期望的格式顯示?如果是這樣,你能描述一下你所看到的與你想看到的內容嗎? – 2012-04-23 15:09:16

+0

沒有錯誤,但數據不顯示,而不是數據null是所有字段下方 – Razia 2012-04-23 15:18:29

+0

所以,你得到一個HTML表,多行,但是所有的數據是'NULL'?或者你是否說明表格丟失? – 2012-04-23 15:22:42

回答

0
<% 
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 
%> 
+0

仍然沒有工作表與空值顯示和你的,如果同時狀態顯示錶上方.. – Razia 2012-04-24 05:21:46

+0

現在就來試試我已經編輯答案 – 2012-04-24 05:39:53

+0

數據仍然沒有隻顯示錶是存在的.. – Razia 2012-04-24 05:54:03