prepared statement
<div align="left">iam trying jdbc concepts like insert ,delete and updation using prepared statements with jsp.
iam having problem with updation and deletion.i have no problem in insertion[ all using prepared statement].During updation and deletion it triggers an sqlexception as,"COUNT field incorrect".i tried with the following code.
could you please help me to solve this problem?
[u]FOR UPDATION </u>
<%@ page language="java" import ="java.sql.*" %>
<%
String empp1=request.getParameter("empp");
String nam1=request.getParameter("nam");
String prtt1=request.getParameter("prtt");
String stdtt1=request.getParameter("stdtt");
String enddtt1=request.getParameter("enddtt");
%>
<html>
<head><title>DELAY TRACKING DETAILS</title>
<script language="javascript">
function fn1()
{
document.fn.action="http://localhost:8000/sbc/plpage.html";
document.fn.submit;
}
</script>
</head>
<body bgcolor="fffff0">
<br><br><br><br>
<%
Connection con=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:eedsn", "","");
PreparedStatement st=con.prepareStatement("update empl set name=?,pr_tit=?,enddt=? where empid=? ");
st.setString(2,nam1);
st.setString(3,prtt1);
st.setString(4,enddtt1);
st.executeUpdate();
}
catch(Exception d)
{
out.println("cannot update the records");
}
%>
<form method=get action="http://localhost:8000/sbc/plpage.html">
<input align=center type=image src="c:\com\sanrm\exit.gif" onclick="fn1()">
</form>
</body>
</html>
[u]FOR DELETION </u>
<%@ page language="java" import ="java.sql.*" %>
<html>
<head><title>Employee Details</title>
</head>
<body bgcolor="fffff0">
<br><br><br><br>
<%
String eidd1=request.getParameter("eidd");
Connection con=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:eedsn", "","");
PreparedStatement st=con.prepareStatement("delete from empl where empid=?");
response.sendRedirect("http://localhost:8000/sannew/pstatus1.jsp");
}
catch(Exception d)
{
out.println("cannot recognize the records"+d);
}
%>
</body>
</html>
</div id="left">
|