Fórum
How to insert mutiple row with single insert statement in liferay
sathya prakash A, modificado 9 Anos atrás.
How to insert mutiple row with single insert statement in liferay
Junior Member Postagens: 67 Data de Entrada: 12/06/12 Postagens Recentes
Hi Frndzs,
I have seven textboxes in my view.jsp page and in my action class i want to insert these seven values into database as seven rows. how to do it.
How to check textbox count values in action class so that i can use loop mechanism and insert the same.
Example:
Textbox values :
100
200
300
400
500
600
700
Insert into tablename values(100);
Insert into tablename values(200);
Insert into tablename values(300);
Insert into tablename values(400);
Insert into tablename values(500);
Insert into tablename values(600);
Insert into tablename values(700);
Please help.....
I have seven textboxes in my view.jsp page and in my action class i want to insert these seven values into database as seven rows. how to do it.
How to check textbox count values in action class so that i can use loop mechanism and insert the same.
Example:
Textbox values :
100
200
300
400
500
600
700
Insert into tablename values(100);
Insert into tablename values(200);
Insert into tablename values(300);
Insert into tablename values(400);
Insert into tablename values(500);
Insert into tablename values(600);
Insert into tablename values(700);
Please help.....
David H Nebinger, modificado 9 Anos atrás.
RE: How to insert mutiple row with single insert statement in liferay
Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentessathya prakash A:
I have seven textboxes in my view.jsp page and in my action class i want to insert these seven values into database as seven rows. how to do it.
Seriously?
How are you accessing your database? Are you using ServiceBuilder, straight JDBC, Hibernate/JPA, EJB?
I mean, this seems to be a java 101 sort of question how you take a value submitted as a parameter and persist it to a database...
Oh, wait, this isn't another job interview question where you're looking for an answer to find a job, is it?
sathya prakash A, modificado 9 Anos atrás.
RE: How to insert mutiple row with single insert statement in liferay
Junior Member Postagens: 67 Data de Entrada: 12/06/12 Postagens Recentes
Hi David,
Oh!! No, its my new requirement david .....
I am using service builder... i am able to store a single textbox value in database but not seven values as a single shot(its overriding).
Example.
2 ->100 - row
4-->200 - row
6-->300 - row
8-->500 - row
10-->1000 - row
Oh!! No, its my new requirement david .....
I am using service builder... i am able to store a single textbox value in database but not seven values as a single shot(its overriding).
Example.
2 ->100 - row
4-->200 - row
6-->300 - row
8-->500 - row
10-->1000 - row
David H Nebinger, modificado 9 Anos atrás.
RE: How to insert mutiple row with single insert statement in liferay
Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentes
Do you call the create() method followed by the add method for each individual value?
Tanweer Ahmed ., modificado 1 Ano atrás.
RE: How to insert mutiple row with single insert statement in liferay
Expert Postagens: 322 Data de Entrada: 11/03/10 Postagens Recentes
Hi Sathya,
Did you try something like below ?
Regards,
Tanweer.
Did you try something like below ?
for (String value : ParamUtil.getParameterValues(actionRequest, "param")) {
YourEntity entity = yourEntityPersistence.create(CounterLocalServiceUtil.increment(YourEntity.class.getName()));
entity.setYourValue(value);
yourEntityPersistence.update(entity);
}
Regards,
Tanweer.
sathya prakash A, modificado 9 Anos atrás.
RE: How to insert mutiple row with single insert statement in liferay
Junior Member Postagens: 67 Data de Entrada: 12/06/12 Postagens Recentes
Dear Friends,
Thanks for your responses.
I achieved the above scenario with my below code snippets.
Working Code:
View.jsp Page
<div><input type="text" name="example[]" value="" placeholder="example" class='Your class name'/>
I am using dynamic textboxes to get all my values with same name [example[]]
IN ACTION PAGE:
String []example=request.getParameterValues("examples[]");
for(int i=0;i<example.length;i++) {
yourclass.setXXXXX(Integer.parseInt(example));
XXXXXXLocalServiceUtil.addXXXXX(yourclas);
}
Thanks for your responses.
I achieved the above scenario with my below code snippets.
Working Code:
View.jsp Page
<div><input type="text" name="example[]" value="" placeholder="example" class='Your class name'/>
I am using dynamic textboxes to get all my values with same name [example[]]
IN ACTION PAGE:
String []example=request.getParameterValues("examples[]");
for(int i=0;i<example.length;i++) {
yourclass.setXXXXX(Integer.parseInt(example));
XXXXXXLocalServiceUtil.addXXXXX(yourclas);
}
Andew Jardine, modificado 9 Anos atrás.
RE: How to insert mutiple row with single insert statement in liferay
Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
Just in case anyone else comes across this, you most certainly do not (and should not) use variableName[] are you input field name. the [] is unecessary. All you have to do is make sure that all your fields (like checkboxes) have the same name.