下面是我的jsp程序没有正确执行。它直接返回异常错误消息。jdbc连接在包含文件中。这里batchcode和ccode是复合键。程序应该首先检查这些是否已经插入到数据库中然后它应该插入。
procedure:
create or replace procedure udp_addbatch(
p_batchcode varchar2,
p_ccode varchar2
)
as
BEGIN
INSERT INTO BATCHES(BATCHCODE,CCODE) VALUES(p_batchcode,p_ccode);
commit;
END ;
/
**jsp file**
<html>
<%@page import="java.sql.*, java.lang.String" %>
<head>
<style type='text/css'>
input{
FONT-FAMILY: Verdana; FONT-SIZE:10pt; color:blue;
}
body{
FONT-FAMILY:Verdana;
FONT-SIZE:10pt;
FONT-WEIGHT:Bold;
}
table{
FONT-FAMILY:Verdana;
FONT-SIZE:10pt;
FONT-WEIGHT:Bold;
}
H1,H2,H3{
FONT-FAMILY:Verdana;
FONT-SIZE:13pt;
FONT-WEIGHT:Bold;
COLOR:BLUE;
}
SELECT {
font-family : verdana; font-size : 9pt; background-color : #FCFCFC; border: 1px solid #000000; color:blue;
}
TEXTAREA {
font-family : verdana; font-size : 9pt; background-color : #FCFCFC; border: 1px solid #000000; color:blue;
}
</style>
</head>
<body bgcolor="white">
<%@include file="jdbcresults.jsp"%>
<%
ResultSet rs=null;
int nr;
CallableStatement cstmt=null;
try
{
String BatchCode=request.getParameter("BatchCode");
String CCode=request.getParameter("CCode");
cstmt=con.prepareCall("{call udp_addbatch(?,?)}");
cstmt.setString(1,BatchCode);
cstmt.setString(2,CCode);
rs=cstmt.executeQuery("select * from Batches where CCode='"+CCode+"' and BatchCode='"+BatchCode+"'");
if (!rs.next())
{
cstmt.executeUpdate();
out.println("<h2 align='center'> Batch and course Successfully added</h2>");
}
else
{
out.println("<h2 align='center'> Batch and Course already Exists</h2>");
out.println("<center><a href='Addbatch.jsp'>Go Back</a></center>");
}
rs.close();
cstmt.close();
con.close();
}
catch(Exception e){ e.printStackTrace();}
out.print("<h2 align='center'>course doesn't exist");
out.println("<center><a href='Addbatch.jsp'>Go Back</a></center>");
}
finally{
// The finally clause is always executed - even in error
// conditions PreparedStatements and Connections will always be closed
try
{
if (cstmt = null)
cstmt.close();
}
catch(Exception e) {}
try
{
if (con = null)
con.close();
}
catch (Exception e){}
}
}
%>
</body>
</html>