File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes insert checked checkbox into table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "insert checked checkbox into table" Watch "insert checked checkbox into table" New topic
Author

insert checked checkbox into table

Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
hi guys

i am preparing a page on which i have used select & checkbox i need now that those all checkbox whicch a re checked their data should be entered into the new table

the checked checkboxes are to be printed on next page which i am getting printed correctly now i ant to insert it into table but as they all are printed through for loop so when i try to insert them into an array they all are either lost or might not be getting properly

Help me to solve this problem

thank you
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

they all are either lost or might not be getting properly


What exactly do you mean by this? Could you please show your code, and highlight where the problem is?


Swastik
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
thanks Swastik for your prompt reply

actually i am checking some checkbox on one page & printing them on another page jsp only

now i need that those checkboxes which are printed are also to be inserted into Postgre SQL table

" I am sorry for inserting my connections in jsp"
my code is :-
one.jsp


two.jsp



thank you if you still cant understand my problem still let me kno please
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
i would like to tell you one more thing i am selecteing many checkbox at a time
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

I understood about sections, that multiple sections can be selected. How about division? Can multiple divisions be selected too? If yes, how do you identify which section comes under which division?
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
thank you for the reply actually i am selecting oly one division under which there are many sections so division is in combo & sections are in chckbox both retrieved from database

thats why i need one division which i can retrieve easily & getting it correctly in my table as i am trying

but the main problem is in sections

looking forward for your reply
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

I made few changes in page2, kindly have a look. I don't have any way to test. Please do keep backup of your existing code.

Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
thanks for your code but there are some problems in this

1)




Syntax error, parameterized types are only available if source
level is 1.5

2)


cannot convert from object to string

i canot understand these errors please help me i think i am usingstruts 1.3 so thats why 1st error is coming

2nd can be solved
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
i have solved 2nd problem nw 1st is the remaining one
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
atlast i found changes that i have to make thanks

let me check if code works or not
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

I was just rechecking the logic, we can probably do it without the iterator too.
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
i cant say anything about code now is it right or not but there two things more

1) i need to insert one more column where i have writen heillo there is one more column retrieved from database ho wto do that please help me


2) it is not inserting into the table my query is right but still it is not inserting

any clue why so is happening
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
how can that be done because i cannot understand this logic this is a little bit tough for me

thank you
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6




rst=s.executeQuery("SELECT sec_code from sec_code where sec_name='"+sec+"'");
Just make sure the field name sec_code is correct, because I don't have any idea about your table design.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

Just change this line

to
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
thanks for the updated code swastik but problem still exists

i have checked my table too

its not insering data into table

2) how to insert onemore clumn after retrieving it form seccode
please help me

thanks for your help till now
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

out.println("Number of records inserted="+updateCount);

What does it print in the above line?
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
no swastik its not printing anything i think please consider your this code without iterator once again


thank you
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
i found that program is not entering if(rst.next)
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

rst=s.executeQuery("SELECT sec_code from sec_code where sec_name='"+sec+"'");

Are you sure about the field name and table name in the above query?
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
yup swastik i amm definitely sure about them they all are correct
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

I asked only because your query had select *. Not entering into that rst.next(), means its somehow failing to execute the query, or it's failing to find any matching record. Now the only way seems for resolving the issue is to surround the entire scripelet code in try, catch. Print the exception and see what it says. Also put one else condition for that if(rs.next()) and put some message to see where the control is going.
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
now i have even changed the name of table but still its not working have a look at new code please



thank you once again
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
i have used both else & try & catch


now its printing else condition

means not entering the if condition

thank you
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
hey swastik i have tried everyu possible combination of try & catch but ist not going into catch means no exception

every tym it goes into else part
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

In page1 the checkbox value is a probably a combination of the section code and section name.



But in page2 you are comparing with the section name

Now consider the value displayed in page1 is 1Section1

But while comparing in page2
the query becomes something like sec_name='<table><tr><td>1</td><td>Section1</td></tr>', isn't it wrong?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

You just print sec and see what you get

Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
hey swastik can you tell me any wy so that i can retrieve sec_code from previous page i.e one.jsp but only those sec_code which are checked

i think the problem is might be due to it cannot match sec_name as it is string


"sec" printing correct values what it should print

thank you
Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
i have changed this code what you have said but still its giving error

i have done it now



now its should give right answer but still not proper reply
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

It won't because the value still has that <table><tr> things, and when you retrieve it using getParameter, it gets the complete <table><tr>tags in the variable, and only because of that you are viewing the rendered content in a tabular format.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6

Considering your last made change in page1, try this once again in page2

Aditi agarwal
Ranch Hand

Joined: Feb 23, 2011
Posts: 225
thank you so much Swastik
this is working perfectly
i just removed table tag & running so gud

thank you so so much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: insert checked checkbox into table