File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Too few parameters.

 
stalin vanama
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 293
Java Mac OS X Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stalin, I changed the topic subject. Please read this and this.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic