473,395 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

multiple data insert...?

44
Hi Friends,
I'm facing a serius problem...in 2 days i have to submit my project and i'm stuck here..please help me...

I'm getting some values from the database from one table say roll_no on one page....and then on that page i'm putting some values in front of that roll_no.
Now I want to store the all data in a another table..
P.S. roll no. are not fixed and that is it can any thing from 1 - 60

here is my code.


Expand|Select|Wrap|Line Numbers
  1. <select size="1" name="subject" style="font-family: Arial; font-size: 10px; color:#0B333C"></select>
  2. <--some value -->
  3. <select size="1" name="month" style="font-family: Arial; font-size: 10px; color:#0B333C"></select>
  4. <--some value-->
  5. <select size="1" name="year" style="font-family: Arial; font-size: 10px; color:#0B333C"></select></tr>
  6. <tr>
  7. <td><input type="submit" value="SUBMIT" name="action"/>
  8.  <table  width="800" border="4" cellpadding="1" cellspacing="1">
  9.     <td>
  10.          <table  width="800" border="2" bordercolor="#FFFFFF" cellpadding="0" cellspacing="0">
  11.               <tr>    <td align="right">
  12.  
  13.             </tr>
  14.             <td>
  15.                     <%!    String stu_roll;%>
  16.                     <%
  17.                     String getsub1 = request.getParameter("subject");
  18.                     String getmonth = request.getParameter("month");
  19.                     String getyear = request.getParameter("year");
  20.                     %>
  21.                     <%
  22.                     try
  23.                     {
  24.                     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  25.                     Connection con = DriverManager.getConnection("jdbc:odbc:lala");
  26.                     Statement stmt = con.createStatement();
  27.                     String str1 = "select roll_no from student where sem_id = (select sem_id from subject where course_id ='bsc_it' and sub_id = '"+getsub1+"')";
  28.                     ResultSet rs  = stmt.executeQuery(str1);
  29.                     %>
  30.                     <table  align="center" width="" cellpadding="0" cellspacing="0" border="1" cellspacing="1" cellpadding="1">
  31.                      <tr>
  32.                     <td><input type="text"  value="Total Lecture" readonly=""/></td>
  33.                     <td><input type="text" name="total_att" maxlength="2"></td>
  34.                      </tr>
  35.                      <tr>
  36.                     <td><input type="text" value="Student roll no." readonly="" /></td>
  37.                      </tr>
  38.                       <%            
  39.                     int no = 0;
  40.                     while(rs.next())
  41.                     {
  42.                     stu_roll = rs.getString("roll_no");
  43.                     no = no + 1;
  44.                     %>
  45.                      <tr bordercolor="#CC3366">
  46.                     <td>
  47.                     <input type="text" name="roll<%=no %>" value="<%= stu_roll %>"  readonly=""/>
  48.                     </td>
  49.                      <td align="center" style="color:#0052A4 ">:</td>
  50.                     <td>
  51.                      <input type="text"  name="att<%=no %>" />
  52.                       <input type="hidden" name="no" value="<%=no %>" />
  53.                     </td>
  54.                     </tr>
  55.  
  56.  
  57.                     <%
  58.                             }
  59.  
  60.                     %>
  61.  
second page from where i'm inserting.

Expand|Select|Wrap|Line Numbers
  1.                                 <%!
  2.                                         int no1 = request.getParameter("no");                                        
  3.                                         int i;
  4.                                 %>
  5.                                 <%
  6.                                         for(i=1;i<no1;i++)
  7.                                         {
  8.                                 %>
  9.                                 <%
  10.                                         String getsub1 = request.getParameter("subject");
  11.                                         String getmonth = request.getParameter("month");
  12.                                         String getyear = request.getParameter("year");
  13.                                         String getatt = request.getParameter("att"+i);
  14.                                         String stu_roll = request.getParameter("roll"+i);
  15.                                 %>
  16.  
  17.  <%
  18.  
  19.  
  20.                                         try
  21.                                         {
  22.                                             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  23.                                             Connection con = DriverManager.getConnection("jdbc:odbc:lala");
  24.                                             PreparedStatement ps=con.prepareStatement("insert into attendance values(?,?,?,?,?,?)");
  25.  
  26.                                             ps.setString(1,stu_roll);
  27.                                             ps.setString(2,getsub1);
  28.                                             ps.setString(3,getmonth);
  29.                                             ps.setString(4,getyear);
  30.                                             ps.setString(5,getatt);
  31.                                             ps.setString(6,"10");
  32.  
  33.                                             ps.executeUpdate();
  34. %>                                            
  35.  
please help me......
Feb 21 '08 #1
9 2309
r035198x
13,262 8TB
1.) You are creating database connections from a JSP, you should separate code that does different things into different modules(classes packages). Code that connects to a database to get data should be written separately from code that displays data and that should be written separately from code that processes data e.t.c
2.) You didn't specify your exact problem.
Feb 21 '08 #2
mak1084
44
1.)
2.) You didn't specify your exact problem.
I dont know whether the method which I'm using is right or wrong. Here I'm using a variable 'no' to count the total roll_no. This variable is also being used in the <input> tag to give a diffrent name for the diffrent values of the roll_no.
but here i'm not able to get the values in next page in getParameter...
and geting this error...


Expand|Select|Wrap|Line Numbers
  1. type Exception report
  2.  
  3. message 
  4.  
  5. description The server encountered an internal error () that prevented it from fulfilling this request.
  6.  
  7. exception 
  8. org.apache.jasper.JasperException: java.lang.NumberFormatException: null
  9.     org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
  10.     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
  11.     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
  12.     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
  13.     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
  14.  
  15.  
  16. root cause 
  17. java.lang.NumberFormatException: null
  18.     java.lang.Integer.parseInt(Unknown Source)
  19.     java.lang.Integer.parseInt(Unknown Source)
  20.     org.apache.jsp.lala.attendance_jsp._jspService(attendance_jsp.java:71)
  21.     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
  22.     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
  23.     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
  24.     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
  25.     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
  26.     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
  27.  
  28. note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.

Is I'm doing in right way???
I think HashMap can also be used here but i have never played with the HashMap..
Feb 21 '08 #3
r035198x
13,262 8TB
In which JSP are you doing the Integer.parseInts? One of them is receiving null as argument( that's what your stack trace says)
Feb 21 '08 #4
mak1084
44
In which JSP are you doing the Integer.parseInts? One of them is receiving null as argument( that's what your stack trace says)
Oh!! I did some change before posting...
here where I chaned it in second jsp.

Expand|Select|Wrap|Line Numbers
  1. <%!
  2.               int no1 = Integer.parseInt(request.getParameter("no"));                              
  3.                                  int i;
  4.                                 %>
  5.                                 <%
  6.                                         for(i=1;i<no1;i++)
  7.                                         {
  8.                                 %>
you can see that in first jsp file i'm sending through a Hidden input.
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" name="no" value="<%=no %>" />
I don't know why its not sending the value to the next page.
Feb 21 '08 #5
r035198x
13,262 8TB
The parameter is never submitted to the second JSP then. Is it on the form that was submitted? If you had separated the Java from the HTML it would have been easy to pick up
Feb 21 '08 #6
BigDaddyLH
1,216 Expert 1GB
I second the plea for you to write better code. JSP should have no database nonsense in it. In fact it should have no Java at all embedded in it! If your database code were separate, it would be so much easier to design, write, debug, maintain and generally understand.

If your instructor is teaching you to write the sort of code you posted, I, well, I can't post the words I'm thinking!
Feb 21 '08 #7
r035198x
13,262 8TB
...., I, well, I can't post the words I'm thinking!
Thinking bad things is not allowed in the public forums.
ADMIN.
Feb 21 '08 #8
mak1084
44
I second the plea for you to write better code. JSP should have no database nonsense in it. In fact it should have no Java at all embedded in it!
You mean that JSP should not have any java code....then how should i use the database?

If your instructor is teaching you to write the sort of code you posted, I, well, I can't post the words I'm thinking!
You can think it coz in college the professor don't know any think. They are not concerned about us, they will just give us internal marks...that all.

can you please send me some code example, so that i can see how to write the code?
Feb 21 '08 #9
BigDaddyLH
1,216 Expert 1GB
You mean that JSP should not have any java code....then how should i use the database?
In the usual way :-)

HTML gets/posts should be handled by a proper servlet, not a jsp. This servlet is a Controller in the MVC pattern. If you are using a framework like Struts or JSF, this servlet is already written for you as part of the framework. It delegates to other objects to handle the request. If database access is required, this is encapsulated in DAOs. The resulting data is stored in beans that are forwarded to a jsp and displayed.

Here's a discussion of some options in architecture: http://java.sun.com/developer/Books/...ges/Chap12.pdf
Feb 21 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: shank | last post by:
I have a recordset that contains multiple records of product a user is purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it...
8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
7
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
3
by: wxbuff | last post by:
I have a report based on our product names that consists of two parts. Both insert data into a temporary table. 1. A single grouped set of results based on all products 2. Multiple tables based...
5
by: Arsen V. | last post by:
Hello, What is the optimal way to insert multiple rows (around 1000) from a web application into a table? The user enters multiple lines into a text box (up to 10,000). The ASP.NET...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
9
by: dan | last post by:
within a loop i am building a sql insert statement to run against my (programatically created) mdb. it works but it seems unreasonably SLOW! Sorry, dont have the code here but the jist is very...
11
by: TechnoAtif | last post by:
INSERT AND UPDATE MULTIPLE CHECKBOX DATA USING PHPMYSQL OR JAVASCRIPT Hi All I want to check the multiple checkboxes update them after revisiting that page. I am taking the name as...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.