New To Java - sql.Exception
plz help me in fixing this error
I got this exception
=============================
java.sql.SQLException: Parameter index out of range (4) number of parameters,which is 3)
=============================
in my database i am having 4 fields first field is auto incremented
and the remaining three i am inserting the values
please help me in fixing this error
thanks
try{
Class.forName("com.mysql.jdbc.Driver");
con= DriverManager.getConnection("jdbc:mysql://553.123.23.540/Bidding","mysql","pennywise");
PreparedStatement ps=con.prepareStatement("insert into User values (?,?,?)");
ps.setString(2,s11);
ps.setString(3,s22);
ps.setString(4,s33);
int i= ps.executeUpdate();
}//try
[1188 byte] By [
saamera] at [2007-11-26 23:21:06]

U are saying first parameter is first and second is.....
OK ,let me know that when i had Auto Incremented the first feild
in the database so (what i think is) it mean that the first field is automatically incremented and the remaining fields ie 2,3,4 i am inserting the values ..So why it is showing the exception as mention above ...PLZ HELP thanks
try this instead:
ps.setString(1,s11); //1 -> first '?'ps.setString(2,s22); //2 -> second '?'
ps.setString(3,s33); //3 -> third '?'
the autoincremented id is inserted automatically.
see this article :
http://www.kitebird.com/articles/jdbc.html
insert into User values (?,?,?)sorry if i miss understood the question, but the problem is with the insert statement, Try this!insert into user ( field1, field2,field3)values (?,?,?)
this the exception again its raising:
java.sql.SQLException:Column count doesn't match value count at row 1
This is the code
package com.pennywise;import java.io.*;
import java.util.*;
import java.sql.*;
public class UserServices1 implements Serializable
{
public UserServices1(){}
public void createProfile(User user)
{
User us=user;
String s11=us.getUserName();
String s22=us.getUserEmailID();
String s33=us.getUserPassword();
Connection con=null;
try{
Class.forName("com.mysql.jdbc.Driver");
con= DriverManager.getConnection("jdbc:mysql://155.677.87.866/Bidding","mysql","pennywise");
PreparedStatement ps=con.prepareStatement("insert into User values (?,?,?)");
ps.setString(1,s11);
ps.setString(2,s22);
ps.setString(3,s33);
int i= ps.executeUpdate();
}//try
catch(Exception e){
e.printStackTrace();
System.out.println(e);
}finally{
try{
con.close();
}catch(Exception e){}
}//finally
}//createProfile
}//UserService1