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
public int 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;
}