Meaningless Drivel is fun!*
The moose likes JSP and the fly likes jsp insert program not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp insert program not working" Watch "jsp insert program not working" New topic
Author

jsp insert program not working

Tuhin Bagh
Greenhorn

Joined: Mar 23, 2012
Posts: 7

Heyya programmers!
i've project work to complete , by short amount of time and the add program is not working! i've attached a sanpshort if the error
And here is the code. By the way the view and delete programs are working superbly, so there is no error on Dsn connection.
And i had crossed checked it, i made sure that there are not blank spaces on the add program :(

HELLLPPPPPPPPPPP please.,,,!!!

Jsp
---------------------------------------------------------
<%@page import="java.sql.*"%>
<%@page import="repeat.dbconnect"%>
<jsp:useBean id="a" class="repeat.dbconnect"/>
<jsp:getProperty name="a" property="conn"/>
<%String S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12,S13,S14,S15,S16,S17;
S1=request.getParameter("T1");
S2=request.getParameter("T2");
S3=request.getParameter("T3");
S4=request.getParameter("T4");
S5=request.getParameter("T5");
S6=request.getParameter("T6");
S7=request.getParameter("T7");
S8=request.getParameter("T8");
S9=request.getParameter("T9");
S10=request.getParameter("T10");
S11=request.getParameter("T11");
S12=request.getParameter("T12");
S13=request.getParameter("T13");
S14=request.getParameter("T14");
S15=request.getParameter("T15");
S16=request.getParameter("T16");
S17=request.getParameter("T17");
int c=Integer.parseInt(S1);
int b=Integer.parseInt(S15);
int k=a.stmt.executeUpdate("insert into Form values("+c+",'"+S2+"','"+S3+"','"+S4+"','"+S5+"','"+S6+"','"+S7+"','"+S8+"','"+S9+"','"+S10+"','"+S11+"','"+S12+"','"+S13+"','"+S14+"',"+b+",'"+S16+"','"+S17+"',)");
%>
<script> alert("Record is inserted");
document.location="../Web/Add.html"
</script>


Html
-----------------------------------------------------------
<html>

<head>
<title>Registration for New Student</title>
</head>

<body>

<table border="1" width="100%">
<tr>
<td colspan="2" height="38">
<p align="center"><b><font size="5">Registration for New Student in
Hostel</font></b></td>
</tr>
<tr>
<td width="35%">Candidate's ID.</td>
<td width="63%"><input type="text" name="T1" size="10"></td>
</tr>
<tr>
<td width="35%">Candidate's Name.</td>
<td width="63%"><input type="text" name="T2" size="33"></td>
</tr>
</table>
<table border="1" width="100%">
<tr>
<td width="35%">Father's Name.</td>
<td width="63%"><input type="text" name="T3" size="33"></td>
</tr>
</table>
<table border="1" width="100%">
<tr>
<td width="35%">Address.</td>
<td width="63%"><textarea rows="4" name="T4" cols="28"></textarea></td>
</tr>
</table>
<table border="1" width="100%">
<tr>
<td width="35%">Parent/Guardian Phone no.</td>
<td width="63%"><input type="text" name="T5" size="20"></td>
</tr>
</table>
<table border="1" width="100%">
<tr>
<td width="35%">Parent/Guardian Mobile no.</td>
<td width="63%"><input type="text" name="T6" size="20"></td>
</tr>
<tr>
<td width="35%">Parent/Guardian Email id (if any).</td>
<td width="63%"><input type="text" name="T7" size="34"></td>
</tr>
</table>
<table border="1" width="100%">
<tr>
<td width="35%">Student Mobile no.</td>
<td width="63%"><input type="text" name="T8" size="20"></td>
</tr>
</table>
<table border="1" width="100%">
<tr>
<td width="35%">Student Email id.</td>
<td width="63%"><input type="text" name="T9" size="34"></td>
</tr>
<tr>
<td width="35%">Blood Group.</td>
<td width="63%"><input type="text" name="T10" size="3"></td>
</tr>
<tr>
<td width="35%">Present illness if any.</td>
<td width="63%"><input type="text" name="T11" size="34"></td>
</tr>
<tr>
<td width="35%">Local Address of Guardian (if any).</td>
<td width="63%"><textarea rows="4" name="T12" cols="28"></textarea></td>
</tr>
<tr>
<td width="35%">Caste.</td>
<td width="63%"><input type="text" name="T13" size="3"></td>
</tr>
<tr>
<td width="35%" height="25">Class in which Studying and the Branch</td>
<td width="63%" height="25"><input type="text" name="T14" size="34"></td>
</tr>
<tr>
<td width="99%" colspan="2">Stays in Room No. With the following
Roommates.</td>
</tr>
<tr>
<td width="35%" height="25">Room No.</td>
<td width="63%" height="25"><input type="text" name="T15" size="4"></td>
</tr>
<tr>
<td width="35%">1)</td>
<td width="63%"><input type="text" name="T16" size="33"></td>
</tr>
<tr>
<td width="35%">2)</td>
<td width="63%"><input type="text" name="T17" size="33"></td>
</tr>
</table>
<form method="POST" action="../Src/Add.jsp">

<p> <input type="submit" value="Submit" name="B1">        
<input type="reset" value="Reset" name="B2">        
</p>
</form>
<form method="POST" action="../Web/Admin.html">
<p><input type="submit" value="Return" name="B3"></p>
</form>

</body>

</html>


[Thumbnail for untitled.JPG]

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Either S1 or S15 is null. Make sure all your parameter names are correct, both in the form and in your JSP page.

That said, there are two other issues here:
1) Your code does not protect against SQL injection. You should use a PreparedStatement instead.
2) You shouldn't add Java code to JSPs anymore. Instead, use a servlet as the form action to perform the processing, then let it redirect to a JSP for displaying the results.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Tuhin Bagh
Greenhorn

Joined: Mar 23, 2012
Posts: 7

Rob Spoor wrote:Either S1 or S15 is null. Make sure all your parameter names are correct, both in the form and in your JSP page.

That said, there are two other issues here:
1) Your code does not protect against SQL injection. You should use a PreparedStatement instead.
2) You shouldn't add Java code to JSPs anymore. Instead, use a servlet as the form action to perform the processing, then let it redirect to a JSP for displaying the results.


Shall i give you my, project stuff?
just copy it in Roots folder of your tomcat!
just i had crossed checked again :( can't find any error. Earlier it was working, donno what happen!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

I don't need your entire project. You only need to show the form that's submitting these values. Or, if you don't use a form, how you're invoking this JSP page instead.
Tuhin Bagh
Greenhorn

Joined: Mar 23, 2012
Posts: 7

Rob Spoor wrote:I don't need your entire project. You only need to show the form that's submitting these values. Or, if you don't use a form, how you're invoking this JSP page instead.

Frist thing first, i had created a system DSN same name as my .accdb name!
and i'm invoking the .jsp file via button on html . i had posted the html page code, :O i can't understand where is the problem!
Shall i write the whole code again..?? What you think Sir Rob


[Thumbnail for untitled.JPG]

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Your input fields are located outside your form. Only fields within the form are submitted. Move your form opening tag to before the table.
Tuhin Bagh
Greenhorn

Joined: Mar 23, 2012
Posts: 7

Rob Spoor wrote:Your input fields are located outside your form. Only fields within the form are submitted. Move your form opening tag to before the table.

OMG!!! how did that silly mistake happened! I feel so noob.
The program worked like a charm :D Thanks a ton Rob :D are you on Facebook or some stuff btw..?? I needs your help, thought my college project is 50% completed..!!
next problem which m facing is a simple login authentication, shall i post here, or shall i post as a new topic..??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Tuhin Bagh wrote:
Rob Spoor wrote:Your input fields are located outside your form. Only fields within the form are submitted. Move your form opening tag to before the table.

OMG!!! how did that silly mistake happened! I feel so noob.
The program worked like a charm :D Thanks a ton Rob :D

You're welcome :)

are you on Facebook or some stuff btw..?? I needs your help, thought my college project is 50% completed..!!
next problem which m facing is a simple login authentication, shall i post here, or shall i post as a new topic..??

I am on Facebook but I only befriend people I know in real life. Please post your problems here, that way you can get help from more people.
As the login issue is a different problem, please create a new topic for it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp insert program not working