| | |
Unsure how to save to database dynamic Textfield values
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2006
Posts: 15
Reputation:
Solved Threads: 0
I'm trying to create a list to record student grades into the database. I'm able to pull out the names from the database and create a table with textfields in it to input the data into.
This is the code i'm using
for(int i = 0; rst2.next(); i++){
.......
<th scope="col"><input name="ca1_<%=i%>" type="text" id="exam1" size="7" /></th>
...
I'm using jsp and mysql
My database fields are exam1, exam2, exam3, exam4
Thank you so much for your help.
This is the code i'm using
for(int i = 0; rst2.next(); i++){
.......
<th scope="col"><input name="ca1_<%=i%>" type="text" id="exam1" size="7" /></th>
...
I'm using jsp and mysql
My database fields are exam1, exam2, exam3, exam4
Thank you so much for your help.
•
•
Join Date: Oct 2006
Posts: 15
Reputation:
Solved Threads: 0



This is what i've tried.
for(int i = 0; rst2.next(); i++){
String ca1 = request.getParameter("ca1_<%=i%>");
String query2 = "INSERT into results(ca1) values ('"+ca1+"')";
stm2.executeUpdate(query2);
}
The error as follows..
String not terminated at end of line.
String ca1 = request.getParameter("ca1_<%=i
JSP Syntax (Toggle Plain Text)
String ca1 = request.getParameter("ca1_<%=i%>");
JSP Syntax (Toggle Plain Text)
String ca1 = request.getParameter("ca1_" + i);
At this point in the code you are already inside a scriptlet tag (at least I assume you are), so additional scriptlet tags are nothing but syntax errors.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Oct 2006
Posts: 15
Reputation:
Solved Threads: 0
Thank you it worked. Now i have another problem. Lets say i want to save all the information as a single string in the database instead of it going into another row. Here is my code. I'm using checkbox now.
for(int i = 0; rst2.next(); i++){
if(request.getParameter("ca1_"+i) !=null){
Childic = rst2.getString("Childic") ;
String query2 = "INSERT into results(ca1) values ('"+Childic+"')";
stm2.executeUpdate(query2);
}
else{
}
}
Thank you so very much for your help.
for(int i = 0; rst2.next(); i++){
if(request.getParameter("ca1_"+i) !=null){
Childic = rst2.getString("Childic") ;
String query2 = "INSERT into results(ca1) values ('"+Childic+"')";
stm2.executeUpdate(query2);
}
else{
}
}
Thank you so very much for your help.
If what you mean, is that you want to concatenate all values into one string and then insert that then change
to
JSP Syntax (Toggle Plain Text)
for(int i = 0; rst2.next(); i++){ if(request.getParameter("ca1_"+i) !=null){ Childic = rst2.getString("Childic") ; String query2 = "INSERT into results(ca1) values ('"+Childic+"')"; stm2.executeUpdate(query2); } else { // whatever it is you want here } }
JSP Syntax (Toggle Plain Text)
for(int i = 0; rst2.next(); i++){ if(request.getParameter("ca1_"+i) !=null){ Childic = Childic + rst2.getString("Childic") ; } else { // whatever it is you want here } } String query2 = "INSERT into results(ca1) values ('"+Childic+"')"; stm2.executeUpdate(query2);
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Oct 2006
Posts: 15
Reputation:
Solved Threads: 0
Got it working. This the code.
rst2 = stm1.executeQuery("select * from students");
String Childic = "";
for(int i = 0; rst2.next(); i++){
if(request.getParameter("ca1_"+i) !=null){
Childic += " " + rst2.getString("Childic") ;
}
String query2 = "INSERT into results(ca1) values ('"+Childic+"')";
stm2.executeUpdate(query2);
Thank you to all who viewed and helped.
rst2 = stm1.executeQuery("select * from students");
String Childic = "";
for(int i = 0; rst2.next(); i++){
if(request.getParameter("ca1_"+i) !=null){
Childic += " " + rst2.getString("Childic") ;
}
String query2 = "INSERT into results(ca1) values ('"+Childic+"')";
stm2.executeUpdate(query2);
Thank you to all who viewed and helped.
![]() |
Similar Threads
- Storing dynamic form values in Arrays for display & insert (PHP)
- preloader for database content possible?? (Graphics and Multimedia)
Other Threads in the JSP Forum
- Previous Thread: Regular Expression
- Next Thread: Problem with update data to database
Views: 4418 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for JSP
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient project read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write






