java.sql.SQLException: Invalid column index

Seems everything is fine but it is giving the following error

java.sql.SQLException: Invalid column index

Let me know where the code is wrong

The code is pasted below

publicint EventsIntranetInsert(DinnerEvents obj)

{

Connection conn =null;

PreparedStatement ps1 =null;

String intranetInsert ="INSERT INTO TEST_EVENTS (EVENT_ID,TITLE,LOCATION,EVENT_DATE,SOURCE_CODE,TICKET_AVAILABILITY,URL,EXTRA_FIELD_NAME_1) "

+"VALUES (?,?,?,?,?,?,?,?)";

boolean intraIns =false;

int eventId = getNextID();

logger.info("DinnerDAO:"+eventId);

int insert = 0;

try{

logger.info("Inserting in the Dinner_events table:");

conn=DinnerDatabase.getDinnerConnection();

ps1=conn.prepareStatement(intranetInsert);

int i=0;

ps1.setInt(i++,eventId);

System.out.println("DinnerDAO:"+i+":::"+eventId);

ps1.setString(i++,obj.getTitle());

System.out.println("DinnerDAO:"+i+":::"+obj.getTitle());

ps1.setString(i++,obj.getLocation());

System.out.println("DinnerDAO:"+i+":::"+obj.getLocation());

ps1.setDate(i++,dateConversion(obj.getEventDate()));

System.out.println("DinnerDAO:"+i+":::"+dateConversion(obj.getEventDate()));

ps1.setString(i++,obj.getSourceCode());

System.out.println("DinnerDAO:"+i+":::"+obj.getSourceCode());

ps1.setString(i++,obj.getTicketAvailFlag());

System.out.println("DinnerDAO:"+i+":::"+obj.getTicketAvailFlag());

ps1.setString(i++,obj.getUrl());

System.out.println("DinnerDAO:"+i+":::"+obj.getUrl());

ps1.setString(i++,obj.getExtraFieldName1());

System.out.println("DinnerDAO:"+i+":::"+obj.getExtraFieldName1());

logger.info(":::::::::"+i);

insert = ps1.executeUpdate();

if(insert > 0){

logger.info("DinnerDAO:After successful inserting in the EventsIntranetInsert");

System.out.println("DinnerDAO:After successful inserting in the EventsIntranetInsert");

intraIns =true;

insert = eventId;

conn.commit();

}

}

catch(Exception e)

{

intraIns=false;

logger.error("Error while inserting dinner_events in the database "+e);

System.out.println("Error while inserting dinner_events in the database "+e);

}

finally

{

try

{

if(ps1!=null){ps1.close();}

if (intraIns=false){conn.rollback();conn.close();}else{conn.commit();conn.close();}

if (conn !=null) conn.close();

}

catch(Exception e)

{

e.printStackTrace();

}

}

return insert;

}

[4612 byte] By [Javauser2004a] at [2007-11-26 20:31:08]
# 1

I wouldn't use i++ here:ps1.setInt(i++,eventId);

unless I remembered whether i++ was the pre-increment operator or the post-increment operator. And even then I wouldn't use it because it renders your code unreadable, at least to the extent that you can't see that you start by callingps1.setInt(0,eventId);

DrClapa at 2007-7-10 1:21:01 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...