aspose file tools*
The moose likes JDBC and the fly likes Exception raised when trying to delete record from database...! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Exception raised when trying to delete record from database...!" Watch "Exception raised when trying to delete record from database...!" New topic
Author

Exception raised when trying to delete record from database...!

Prakash Chidambaram
Greenhorn

Joined: Oct 17, 2000
Posts: 7
Hi Friends,
I am presently working on a project involving JSP and MSAccess using JDBC-ODBC bridge. I can easily add, modify, view the values. But when i try to delete the same i get the follg. exception
"java.sql.SQLException: [Microsoft][ODBC Microsoft Access 97
Driver]Wrong number of parameters test value"
I don't get it.. Pls. help me to recover from this error.

My Code:
-------
<%@ page language="java" import="java.sql.*,java.io.*" %>
<%!<br /> String k="";<br /> String check="";<br /> String DeleteValues() {<br /> try {<br /> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");<br /> Connection con=DriverManager.getConnection("jdbc dbc:sara","","");<br /> PreparedStatement ps=con.prepareStatement("delete person where name=?");<br /> ps.executeUpdate();<br /> con.close();<br /> }catch (Exception e) {return e.toString();}<br /> return "values deleted from database..";<br /> }<br /> %>
<%<br /> k=request.getParameter("submit");<br /> if (k.equals("Yes")) {<br /> check=request.getParameter("name");<br /> out.println("<body>"+DeleteValues()+"</body>");<br /> out.println("<body>"+check+"</body>");<br /> }<br /> %>
With thanks,
prakash.
John Bateman
Ranch Hand

Joined: Mar 09, 2000
Posts: 320

Hi
You never set the value of you input parameter in your query.
Try this..

This now passes John to the (1st) input parameter denoted by the ?.
Hope this helps.
[This message has been edited by Thomas Paul (edited March 02, 2001).]


SOURCE CODE should be SURROUNDED by "code" tags.
 
Don't get me started about those stupid light bulbs.
 
subject: Exception raised when trying to delete record from database...!