File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Too few parameters. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Too few parameters." Watch "Too few parameters." New topic

Too few parameters.

stalin vanama

Joined: Sep 15, 2005
Posts: 2
I am executing the following Program.

<%@ page import="java.util.*,*,javax.servlet.http.*,javax.servlet.*,java.sql.*,java.sql.ResultSet.*" session="true" %>


<html><head><title>Upadting Values</title></head>

<body bgcolor="#FCFCFO">

<b><a href="add.jsp" style="text-decoration:none">Add Account Details!</a>


<a href="val.jsp" style="text-decoration:none"> Display!</a>


<a href="login.jsp" style="text-decoration:none"> Logout!</a></b>





Connection con=null;


con = DriverManager.getConnection("Jdbc dbc:vsr","","");

Statement st = con.createStatement();

out.println("Connection Established <br>");

ResultSet rs = st.executeQuery("UPDATE accounts SET acountname = accountname,startdate = startdate,balance = balance,address = address WHERE accountno = accountno");

out.println("<b>Record Updated</b>");

System.out.println("Connection closed");

}catch(SQLException e)
out.println("SQLException: " + e.getMessage() + "<BR>");
while((e = e.getNextException()) != null)
out.println(e.getMessage() + "<BR>");


I am getting following error:

SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

[bear edit: removed 'urgent']
[ September 15, 2005: Message edited by: Bear Bibeault ]
Dave Salter
Ranch Hand

Joined: Jul 20, 2005
Posts: 293

Your SQL is invalid because you are not specifying any real values for parameters.

Consider using a PreparedStatement instead which will get around this issue and is arguably better practice anyway.
Charu Singh

Joined: Jun 10, 2005
Posts: 20

That's right , try to use a prepared statement using its setString(),setInteger(),setDate() etc. to set the values. Or if you use this as it is then your query should be something like,

stat.executeQuery("update accounts set accountname='"+ accountname+ "',startdate='" + startdate+ "',balance='" + balance+ "',address='"+ address + "' where accountno=" + accountno+ ";");
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

Stalin, I changed the topic subject. Please read this and this.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Too few parameters.
It's not a secret anymore!