Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

PreparedStatement.setObject not working as expected  RSS feed

 
Greenhorn
Posts: 29
1
Eclipse IDE Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, 
I am using Java 8 with JDBC mysql driver 5.1.45

I use a prepare statement to save data in the database , because sometimes I will need to insert null values into some columns, I decided to use setObject.
But it is not working as expected.



I am printing the values that are in my object, just to be sure those fields have data, I am able to see the field values.
But when the prepare statement is executed and the data is inserted into the database, some columns have the values that I was expecting.  But many columns don't have the values that I was expecting to see, they appear with null values.

Any clue about what is happening and how to solve it?


 
author & internet detective
Marshal
Posts: 38151
617
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's start with some problem isolation. Can you create a prepared statement that just updates one field and illustrates the error?

Then share the SQL you pass to prepared statement and the schema for that column in the table.
 
Fernando Guerrero
Greenhorn
Posts: 29
1
Eclipse IDE Java Redhat
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The table where I was inserting the data had a insert trigger. This trigger was running a sql code that was messing the results. This was the problem.
I removed the trigger and now I am seeing in the table the data I was expecting to see.

Thanks for your replay
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 38151
617
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting! Have a cow for sharing that root cause.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!