I just want to update my table using custom sql in liferay 6.1, I have table with primary key auto increment not null. So whenever I am trying to update It creates a new row and instead of updating data it generate a new row. Please help me to update data using custom sql and my database is mysql.
thanks
asif aftab
Related
I am selecting the id using
SELECT SCRTY_RISK_AREA_UI_AREA_ID_SQ.nextval as\"riskAreaNo\" FROM DUAL
This sql query from the database.
Now I need to update the name and description of the already existing data along with the id
UPDATE SCRTY_RISK_AREA
SET AREA_NAME= :areaName, AREA_DESC= :areaDesc,IS_ACTIVE='N'
WHERE UI_AREA_ID = :uiareaId");
Am updating using the above query.
Can anybody help me how to insert or generate the new id. am new to sql not sure how to generate new id
I am not sure how to update along with the id since i generate the id using sequence
If you're inserting a new row, then
insert into scrty_risk_area (id, area_name) values
(scrty_risk_area_ui_area_id_sq.nextval, :areaName);
If you're updating existing ID values (probably not a good idea, especially if it is a primary key, not to mention if it is referenced by some foreign keys):
update scrty_risk_area set
id = scrty_risk_area_ui_area_id_sq.nextval;
I have one problem. Two DB's(say DB1 & DB2) are talking to each other.
In DB1 particular row is updated, so I just want to detect the changes from the DB2 and update the new row in DB2.
Please let me know how to di this using JPA/Hibernate.
You can create Rest API for update the new rows! Create database triggers in DB1, in the body of triggers write HttpClient for calling the Rest API and update the particular row in DB2.
I have an update query which I am trying to execute through batchUpdate method of spring jdbc template. This update query can potentially match 1000s of rows in EVENT_DYNAMIC_ATTRIBUTE table which needs to be get updated. Will updating thousands of rows in a table cause any issue in production database apart from timeout? like, will it crash database or slowdown the performance of entire database engine for other connections...etc?
Is there a better way to achieve this instead of firing single update query in spring JDBC template or JPA? I have the following settings for jdbc template.
this.jdbc = new JdbcTemplate(ds);
jdbc.setFetchSize(1000);
jdbc.setQueryTimeout(0); // zero means there is no limit
The update query:
UPDATE EVENT_DYNAMIC_ATTRIBUTE eda
SET eda.ATTRIBUTE_VALUE = 'claim',
eda.LAST_UPDATED_DATE = SYSDATE,
eda.LAST_UPDATED_BY = 'superUsers'
WHERE eda.DYNAMIC_ATTRIBUTE_NAME_ID = 4002
AND eda.EVENT_ID IN
(WITH category_data
AS ( SELECT c.CATEGORY_ID
FROM CATEGORY c
START WITH CATEGORY_ID = 495984
CONNECT BY PARENT_ID = PRIOR CATEGORY_ID)
SELECT event_id
FROM event e
WHERE EXISTS
(SELECT 't'
FROM category_data cd
WHERE cd.CATEGORY_ID = e.PRIMARY_CATEGORY_ID))
If it is one time thing, I normally first select the records which needs to be updated and put in a temporary table or in a csv, and I make sure that I save primary key of those records in a table or in a csv. Then I read records in batches from temporary table or csv, and do the update in the table using the primary key. This way tables are not locked for a long time and you can have fixed set of records added in the batch which needs update and updates are done using primary key so it will be very fast. And if any update fails then you know which records got failed by logging out the failed records primary key in a log file or in an error table. I have followed this approach many time for updating millions of records in the PROD database, as it is very safe approach.
javaFunctions(recomm).writerBuilder("recommender", "recommendations_wkg",
mapToRow(Recommendations_wkg.class))
.saveToCassandra();
The code insert into the table but won't update it. If the column exist it inserts a new one. I want to update if I have different info.
I'm tring to create a table in mysql from java desktop program but I obtain a MySqlSyntaxErrorException.
The query is :
CREATE TABLE FileXFascia(fila0 Integer,fila1 Integer,fila2 Integer,fila3 Integer) VALUES ('3','4','3','3')
Anyone knows where I'm wrong?
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES ('3','4','3','3')' at line 1
You need to split these as follows:
CREATE TABLE FileXFascia(fila0 Integer,fila1 Integer,fila2 Integer,fila3 Integer);
INSERT INTO FileXFascial (fila0, fila1, fila2, fila3) VALUES ('3','4','3','3');
In your question there are two different operations on a table, You are trying to create and insert data in single query even in a wrong way. First you need to create table then insert data into created table. Like below syntax.
create table tableName(col1 dataType,col2 dataType,col3 dataType,.......coln dataType);
After creation of table now you can insert data into table. Like below syntax.
insert into tableName(col1, col2,col3,......coln) values ('data1','data2','data3',......'datan');