wood burning stoves 2.0*
The moose likes JDBC and the fly likes Too few parameters. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Too few parameters." Watch "Too few parameters." New topic
Author

Too few parameters.

stalin vanama
Greenhorn

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

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

</b><br><br>

<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>

<hr>

<%

try

{

Connection con=null;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

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:

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: 292

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
Greenhorn

Joined: Jun 10, 2005
Posts: 20
Hi,

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
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Too few parameters.
 
Similar Threads
Trouble connecting to MS Access via ODBC
Connection Pooling
submit button is not working
please help me
CSS is not coming into effect