• Post Reply Bookmark Topic Watch Topic
  • New Topic

inserting multiple rows in database from struts 2  RSS feed

 
Ranch Hand
Posts: 39
Java PHP Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,
I am developing struts 2 application using oracle 1og database.
I have a form with 4 rows of data.
when I am inserting data then all the data is inserting in same row with 'commas' in database inplace of saving in different rows. How to resolve it...
Thanks in advance...

action class..



getter and setter class....


 
Bartender
Posts: 9462
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, we usually don't put database code in an Action. Have a look at this HowTo (yes, it's Struts 1, but the philosophy still applies).
Second, when you say:

all the data is inserting in same row with 'commas' in database inplace of saving in different rows


are you saying one field gets all the values for a particular row or you are only getting one row inserted when you expect 4?
Finally, If you have 4 rows in your form, you have to configure your form and action so Struts knows there are multiple rows and has someplace to put them. Since you only have one bpv_insert_data in your action, I assume you have not done this. Start with this example (again, Struts 1, but the principles still apply). By the way, you don't have to create an instance of bpv_insert_data. Struts will do that automatically.
 
Saumitra Tiwari
Ranch Hand
Posts: 39
Java PHP Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and thank you very for the advice, all that you said , I will try to frame myself, but my main problem still exist, actually I have practically no idea about struts 1(3 months in struts 2),so can you please suggest some documents on struts 2...
and thanks for reply and please do reply...
 
Ranch Hand
Posts: 93
Java Python Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using an IDE, try creating breakpoints and debug the code line by line to identify the exact problem.
 
Joe Ess
Bartender
Posts: 9462
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Karthik Jayachandran wrote:If you are using an IDE, try creating breakpoints and debug the code line by line to identify the exact problem.



I don't think a debugger would help solve the design problem we are facing here.

@Saumitra: If you need a Struts 2-specific example, there are many on the 'net. Just search for "struts 2 indexed properties"
 
Saumitra Tiwari
Ranch Hand
Posts: 39
Java PHP Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Joe Ess : the example that you are telling is done the same ,which is required, if yes then wait and let me study example, maybe that could help.let's see if I can catch logic or not....
 
Saumitra Tiwari
Ranch Hand
Posts: 39
Java PHP Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is how data is inserted in database....(please see attachment)
I want values in different rows....
db.jpg
[Thumbnail for db.jpg]
 
Joe Ess
Bartender
Posts: 9462
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Saumitra Tiwari wrote:I want values in different rows....



I'm still not quite grasping the problem. I think you have two issues:
1. You are submitting a form with 4 rows of data but the application is only creating one row in the database. If this is true, my first post in this topic has a link to the solution for that: indexed properties.
2. Each column in the row in the database contains all the values separated by commas. The way I understand SQL INSERT is that you can specify the column values in the VALUES statement and you don't have to specify the column names, so your SQL statement appears to be correct. I have the following questions:
2.1. Have you tried executing the statement in SQL Plus or some other SQL console?
2.2. Have you tried specifying the column names in the SQL query?
2.3. Why are you calling ps.cancel()? That aborts whatever command is being executed, so at the least, it does nothing (coming after the con.commit()). At worst, it is rolling back whatever work you have done.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!