• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PreparedStatement Problem

 
Mike London
Ranch Hand
Posts: 1227
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting a NullPointerException when I try to set the first '?' in my prepared statement below.
I'm not sure the syntax is correct.
Also, I'm using SQL Server with an identity key for the first field. Since that first field is auto-generated by SQL Server, I am *not* listing it in the INSERT statement below. (IOW, there are 7 fields in the table, but I'm only specifying 2 through 7 below).
Can anyone see why this statement is failing?
I appreciate any help or advice.
Thanks.
-- Mike

================================================
PreparedStatement updateSchedule = null;
String updateString =
"INSERT INTO schedule VALUES (?,?,?,?,?,?)";
try
{
this.con.prepareStatement(updateString);
updateSchedule.setInt(1,userFK); // NullPointerException happens here.
updateSchedule.setTimestamp(2, sql_evtDate );
updateSchedule.setTimestamp(3, sql_evtDate );
updateSchedule.setTimestamp(4, sql_mtpd );
updateSchedule.setString(5, recurringType);
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

That'll give you a NullPointer every time!
When you call 'prepareStatement', you need to assign the result to the updateSchedule variable.
Dave
 
Mike London
Ranch Hand
Posts: 1227
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You were right.
Making the change you indicated fixed the problem.
Thanks much!!!
--Mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic