下面是jsp中的COUNT个SQL语句。正如您所看到的,我的学生级别下拉列表将显示每个级别的计数。如果用户点击其中一个下拉列表,那么如果学生级别达到最多5个人,系统将生成警报消息,但我没有这样做。我认为我的方法是错误的。请帮助我实现它。
<%
try{
Connection conn = connectionManager.getConnection();
String searchQuery = "Select count(studentlevel) AS COUNTER1 FROM student WHERE studentlevel = '1'";
OraclePreparedStatement pst = (OraclePreparedStatement) conn.prepareStatement(searchQuery);
OracleResultSet rs = (OracleResultSet) pst.executeQuery();
String searchQuery2 = "Select count(studentlevel) AS COUNTER2 FROM student WHERE studentlevel = '2'";
OraclePreparedStatement pst2 = (OraclePreparedStatement) conn.prepareStatement(searchQuery2);
OracleResultSet rs2 = (OracleResultSet) pst2.executeQuery();
String searchQuery3 = "Select count(studentlevel) AS COUNTER3 FROM student WHERE studentlevel = '3'";
OraclePreparedStatement pst3 = (OraclePreparedStatement) conn.prepareStatement(searchQuery3);
OracleResultSet rs3 = (OracleResultSet) pst3.executeQuery();
%>
<div class="select-wrapper">Student Level:
<select name="studentlevel" id="studentlevel" required>
<option value="">- Student Level -</option>
<%
while(rs3.next()){
System.out.println("The sql : "+searchQuery3);
count3 = rs3.getString(1);
%>
<option value="3">3 [<%= count3 %>/5]</option>
<p id="message5"></p>
<%} %>
<%
while(rs2.next()){
System.out.println("The sql : "+searchQuery2);
count2 = rs2.getString(1);
%>
<option value="2">2 [<%= count2 %>/5]</option>
<p id="message6"></p>
<%} %>
<%
while(rs.next()){
System.out.println("The sql : "+searchQuery);
count1 = rs.getString(1);
%>
<option value="1">1 [<%= count1 %>/5]</option>
<p id="message7"></p>
<%} %>
</select>
</div>
JAVASCRIPT
<script>
var c, d, e, text5, text 6, text7;
c = document.getElementById("count3").value;
d = document.getElementById("count2").value;
e = document.getElementById("count1").value;
if(c>0 || c<=5)
{
text5 = "The Class is Already Full, Please Contact the Clerk for Futher Information.";
}
else
{text5= "";
}
if(d>0 || d<=5)
{
text6 = "The Class is Already Full, Please Contact the Clerk for Futher Information.";
}
else
{text6= "";
}
if(e>0 || e<=5)
{
text7 = "The Class is Already Full, Please Contact the Clerk for Futher Information.";
}
else
{text7= "";
}
document.getElementById("message5").innerHTML = text5;
document.getElementById("message6").innerHTML = text6;
document.getElementById("message7").innerHTML = text7;
</script>