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. -
<select size="1" name="subject" style="font-family: Arial; font-size: 10px; color:#0B333C"></select>
-
<--some value -->
-
<select size="1" name="month" style="font-family: Arial; font-size: 10px; color:#0B333C"></select>
-
<--some value-->
-
<select size="1" name="year" style="font-family: Arial; font-size: 10px; color:#0B333C"></select></tr>
-
<tr>
-
<td><input type="submit" value="SUBMIT" name="action"/>
-
<table width="800" border="4" cellpadding="1" cellspacing="1">
-
<td>
-
<table width="800" border="2" bordercolor="#FFFFFF" cellpadding="0" cellspacing="0">
-
<tr> <td align="right">
-
-
</tr>
-
<td>
-
<%! String stu_roll;%>
-
<%
-
String getsub1 = request.getParameter("subject");
-
String getmonth = request.getParameter("month");
-
String getyear = request.getParameter("year");
-
%>
-
<%
-
try
-
{
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
Connection con = DriverManager.getConnection("jdbc:odbc:lala");
-
Statement stmt = con.createStatement();
-
String str1 = "select roll_no from student where sem_id = (select sem_id from subject where course_id ='bsc_it' and sub_id = '"+getsub1+"')";
-
ResultSet rs = stmt.executeQuery(str1);
-
%>
-
<table align="center" width="" cellpadding="0" cellspacing="0" border="1" cellspacing="1" cellpadding="1">
-
<tr>
-
<td><input type="text" value="Total Lecture" readonly=""/></td>
-
<td><input type="text" name="total_att" maxlength="2"></td>
-
</tr>
-
<tr>
-
<td><input type="text" value="Student roll no." readonly="" /></td>
-
</tr>
-
<%
-
int no = 0;
-
while(rs.next())
-
{
-
stu_roll = rs.getString("roll_no");
-
no = no + 1;
-
%>
-
<tr bordercolor="#CC3366">
-
<td>
-
<input type="text" name="roll<%=no %>" value="<%= stu_roll %>" readonly=""/>
-
</td>
-
<td align="center" style="color:#0052A4 ">:</td>
-
<td>
-
<input type="text" name="att<%=no %>" />
-
<input type="hidden" name="no" value="<%=no %>" />
-
</td>
-
</tr>
-
-
-
<%
-
}
-
-
%>
-
second page from where i'm inserting. -
<%!
-
int no1 = request.getParameter("no");
-
int i;
-
%>
-
<%
-
for(i=1;i<no1;i++)
-
{
-
%>
-
<%
-
String getsub1 = request.getParameter("subject");
-
String getmonth = request.getParameter("month");
-
String getyear = request.getParameter("year");
-
String getatt = request.getParameter("att"+i);
-
String stu_roll = request.getParameter("roll"+i);
-
%>
-
-
<%
-
-
-
try
-
{
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
Connection con = DriverManager.getConnection("jdbc:odbc:lala");
-
PreparedStatement ps=con.prepareStatement("insert into attendance values(?,?,?,?,?,?)");
-
-
ps.setString(1,stu_roll);
-
ps.setString(2,getsub1);
-
ps.setString(3,getmonth);
-
ps.setString(4,getyear);
-
ps.setString(5,getatt);
-
ps.setString(6,"10");
-
-
ps.executeUpdate();
-
%>
-
please help me......
9 2309
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.
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... - type Exception report
-
-
message
-
-
description The server encountered an internal error () that prevented it from fulfilling this request.
-
-
exception
-
org.apache.jasper.JasperException: java.lang.NumberFormatException: null
-
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
-
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
-
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
-
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
-
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
-
-
-
root cause
-
java.lang.NumberFormatException: null
-
java.lang.Integer.parseInt(Unknown Source)
-
java.lang.Integer.parseInt(Unknown Source)
-
org.apache.jsp.lala.attendance_jsp._jspService(attendance_jsp.java:71)
-
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
-
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
-
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
-
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
-
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
-
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
-
-
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..
In which JSP are you doing the Integer.parseInts? One of them is receiving null as argument( that's what your stack trace says)
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. - <%!
-
int no1 = Integer.parseInt(request.getParameter("no"));
-
int i;
-
%>
-
<%
-
for(i=1;i<no1;i++)
-
{
-
%>
you can see that in first jsp file i'm sending through a Hidden input. -
<input type="hidden" name="no" value="<%=no %>" />
I don't know why its not sending the value to the next page.
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
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!
...., I, well, I can't post the words I'm thinking!
Thinking bad things is not allowed in the public forums.
ADMIN.
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?
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 Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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,...
|
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,
|
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...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
|
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...
|
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...
|
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,...
| |