• 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.setObject not working as expected

 
Ranch Hand
Posts: 36
3
Eclipse IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 36
3
Eclipse IDE Redhat Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting! Have a cow for sharing that root cause.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic