Hello, I am creating a project where I parse an xml page (feed from a website) in a javabean file and I insert the parsed data in a mysql database. I want this data that gets inserted into the database to be shown in my project when it deploys (the project is jsf and I am using NetBeans). What I want to ask is how can I update the data of the database only when the xml page has new data, because what happens now is that every time I refresh my page, the same data gets inserted again in my database. For example, my xml page has 10 entries. So, when I first deploy my page 10 rows are inserted into the table of my database. But if I refresh my page (by pressing a button), the 10 rows are again inserted into my table and so now I have 20 rows with the same data twice. Can anyone help my with this please?How do I check and insert into the database data that isn't already in it??Also, is there a way to set a fixed number of rows for a table?For example, I could have my table to have only 10 rows, and then use the "Update" function to always update these 10 rows. But is this possible?
Update the database only when new data
Collapse
X
-
You need to check for existance of the records in the table before inserting based on a particular field. Insert only if that does not exists. Update otherwise. -
Originally posted by mariazAlso, is there a way to set a fixed number of rows for a table?For example, I could have my table to have only 10 rows, and then use the "Update" function to always update these 10 rows. But is this possible?
You need to do as debasisdas suggested. You can also use INSERT IGNORE or REPLACE statements. But for these to work you must have some unique key which you don't have according to your current scenario.Comment
Comment