• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PreparedStatement Problem

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You were right.
Making the change you indicated fixed the problem.
Thanks much!!!
--Mike
 
reply
    Bookmark Topic Watch Topic
  • New Topic