Forums Register Login

PreparedStatement Problem

+Pie Number of slices to send: Send
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);
+Pie Number of slices to send: Send

That'll give you a NullPointer every time!
When you call 'prepareStatement', you need to assign the result to the updateSchedule variable.
Dave
+Pie Number of slices to send: Send
You were right.
Making the change you indicated fixed the problem.
Thanks much!!!
--Mike
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 883 times.
Similar Threads
MySQL 4.0.17 PreparedStatement Fails!
Inserting date into an MS Access DB
inserting a row when there is a sequence in that table
To insert value from text field into MySQL database
Prepared statements with % wildcards
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:51:27.