• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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: 38659
677
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: 38659
677
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!