JSP,JDBC and HTML(Very Urgent)

Ads

 
 

Share on Google+Share on Google+

Ragavendran.R
JSP,JDBC and HTML(Very Urgent)
1 Answer(s)      9 years ago
Posted in : JSP-Servlet
Ads
View Answers

July 9, 2008 at 4:08 PM


Hi raghavendran, I completed the code:

I am not using any html. I used only jsp & jdbc.

HOme Page:
FindEmp.jsp

<%@ page language="java" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.sql.*" %>

<HTML>

<BODY BGCOLOR="LIGHTYELLOW">
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:Employee","","");
Statement stmt=null;
%>
<FORM METHOD="GET" ACTION="process.jsp">

<H3> <P ALIGN="CENTER"> <FONT SIZE=6> EMPLOYEE DETAILS </FONT> </P> </H3> </BR> </BR>
<BR>
<BR>
<TABLE CELLSPACING=5 CELLPADDING=5 BGCOLOR="LIGHTBLUE" COLSPAN=2 ROWSPAN=2 ALIGN="CENTER">
<TR>
<TD> <FONT SIZE=5> Enter Employee ID </TD>
<TD> <INPUT TYPE="TEXT" ID="id" NAME="id"> </FONT> </TD>
</TR>
<TR>
<TD> <FONT SIZE=5> Enter Employee Name </TD>
<TD><INPUT TYPE="TEXT" ID="name" NAME="name"> </FONT> </TD>
</TR>
<TR>
<TD> <FONT SIZE=5> Enter New Name (For UPDATE only) </TD>
<TD><INPUT TYPE="TEXT" NAME="nname"> </FONT> </TD>
</TR>
<TR>
<TD>Employee Ids: <SELECT NAME="empIds" ONCHANGE="document.getElementById('id').value=this.options[this.selectedIndex].text"><option>Select One</option>
<%
String rec="SELECT Emp_code,Emp_name FROM Employee";
try {
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(rec);
while(rs.next())
{
%>
<option><%= rs.getInt(1)%></option>
<%}
}
catch(Exception e){System.out.println(e);}
%>
</SELECT>
</TD>
</TR>
<TR> <FONT SIZE=6> <B>
<TD><INPUT TYPE="RADIO" NAME="r1" VALUE="add" >Insert </TD>
</TR>
<TR>
<TD><INPUT TYPE="RADIO" NAME="r1" VALUE="del" >Delete </TD>
</TR>
<TR>
<TD><INPUT TYPE="RADIO" NAME="r1" VALUE="mod" >Update </TD>
</TR>
<TR>
<TD><INPUT TYPE="RADIO" NAME="r1" VALUE="query">Query </TD>

</TR>
</FONT> </B>
<TR> <TD><INPUT TYPE="SUBMIT" VALUE="Submit"> <INPUT TYPE="RESET" VALUE="Reset"> </TD>
</TR>
<%
if(session.getAttribute("empcode")!=null && session.getAttribute("empname")!=null)
{
%>
<script language="javascript">
document.getElementById('id').value=<%=session.getAttribute("empcode").toString()%>
document.getElementById('name').value='<%=session.getAttribute("empname").toString()%>'
</script>
<%
session.removeAttribute("empcode");
session.removeAttribute("empname");
}%>
</FORM>

</BODY>
</HTML>


Note: Please align textboxes & combo box according to ur requirement.

process.jsp:

<%@ page language="java" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.sql.*" %>


<html>
<body>
<%
Connection con=null;
Statement stmt=null;
//ResultSet rs=null;
String radioSelected=request.getParameter("r1");
String name=request.getParameter("name");
String code=request.getParameter("id");

String query=null;
int EmpID=Integer.parseInt(code);
int status;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Employee","","");
stmt=con.createStatement();
if(radioSelected.equals("add")){
query="INSERT INTO Employee (Emp_code,Emp_name) VALUES("+EmpID+",'"+name+"')";
status=stmt.executeUpdate(query);
if(status==1){//This is for successful insertion
%>
<script language="javascript">
alert("Insertion successful");
document.location="FindEmp.jsp";
</script>
<%
}else{
%>
<script language="javascript">
alert("Insertion Failed");
document.location="FindEmp.jsp";
</script>
<% }
}
else if(radioSelected.equals("del")){
query="DELETE * FROM Employee where Emp_code="+EmpID+"";
status=stmt.executeUpdate(query);
if(status==1){//This is for successful Deletion
%>
<script language="javascript">
alert("Deletion successful");
document.location="FindEmp.jsp";
</script>
<%
}else{
%>
<script language="javascript">
alert("Deletion Failed Bcoz,Employee Id Not Found");
document.location="FindEmp.jsp";
</script>
<% }

}
else if(radioSelected.equals("mod")){
String new_name=request.getParameter("nname");
query="UPDATE Employee SET Emp_name='"+new_name+"' where Emp_code="+EmpID+"";
status=stmt.executeUpdate(query);
if(status==1){//This is for successful updation
%>
<script language="javascript">
alert("Record Updated successfully");
document.location="FindEmp.jsp";
</script>
<%
}else{
%>
<script language="javascript">
alert("Updation Failed");
document.location="FindEmp.jsp";
</script>
<% }
}
else if(radioSelected.equals("query")){
query="Select Emp_code, Emp_name from Employee where Emp_code="+EmpID+"";
ResultSet rs=stmt.executeQuery(query);

if(rs.next()) //If record found....
{
session.setAttribute("empcode",rs.getInt(1));
session.setAttribute("empname",rs.getString(2));
%>
<script language="javascript">
document.location="FindEmp.jsp";
</script>
<%
}
else{
%>
<script language="javascript">
alert("Employee Id Not Found");
document.location="FindEmp.jsp";
</script>
<%}
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
con.close();
stmt.close();
//rs.close();
}

%>
</body>
</html>


For query radio button, i changed slightly. Not immediately after clicking the radio button, after selecting the radio button then click submit button. Then it displays selected employee id details.

I didn't do any validations for ur text boxes like number only allowed for employee id text box etc.

Thanks
Sreenivas

Ads









Related Tutorials/Questions & Answers:
JSP,JDBC and HTML(Very Urgent) - JSP-Servlet
JSP,JDBC and HTML(Very Urgent)  Respected Sir/Madam, Thanks... details from database using JDBC and JSP. The home page i.e HTML Page must contain... the code: I am not using any html. I used only jsp & jdbc. HOme Page
very urgent
very urgent  ** how to integrate struts1.3 ,ejb3,mysql5.0 in jboss server with myeclipse IDE
Advertisements
jsp - JDBC
jsp  -------------------------------------------------------------------------------- how to receive data into jsp from html for dropdown boxes
jsp - JDBC
JSP Storing Data, Datatype vale in SQL   Storing Data, Datatype vale...;<%Connection con = null; String url = "jdbc:mysql://localhost:3306..., will help you in storing date in sql database.See how to insert data from html
Very Very Urgent -Image - JSP-Servlet
Very Very Urgent -Image  Respected Sir/Madam, I am R.Ragavendran.. I am working with JSP and JDBC.. In the home JSP page, there is a button... ID) inside the text box of my home JSP page.. How to check whether
jsp-jdbc - JDBC
jsp-jdbc  Hi! html- jsp-jdbc program from the html form where... jsp frequently. I am getting error through request.getParameter(). can you please... should I pass request.getParameter or fname, lname, add,phones (from html input
Query regarding JSP, JDBC
Query regarding JSP, JDBC  can I get the code for the question asked by me regarding JSP,JDBC
Pop up Very Very Urgent - JSP-Servlet
='' Its Very Urgent.. Please send me the coding asap.. Thanks...Pop up Very Very Urgent  Respected Sir/Madam, I am R.Ragavendran.. I got your reply.. Thank you very much for the response. Now I am sending
Help Very Very Urgent - JSP-Servlet
requirements.. Please please Its Very very very very very urgent... Thanks...Help Very Very Urgent  Respected Sir/Madam, I am sorry..Actually.../jsp/ Thanks.   function trim(stringToTrim
Jsp,JDBC - JDBC
Jsp,JDBC  Write a Program using Servlet,JSP, JDBC and XML to create a web application for a courier company to provide an online help in tracking the delivery status of items.  Hi friend, For solving the problem
jsp jdbc Spring
jsp jdbc Spring  I need to create the form in jsp with one field.The field is user id. On submitting the form all the details associated... how to link the user id field of jsp with the database using spring mvc
JSP and AJAX- very urgent - Ajax
JSP and AJAX- very urgent  Respected Sir/Madam, I am Ragavendran.. I have a simple doubt.. At present, I am in a module of the project... Plz its very very Urgent.. Regards, Ragavendran
Program Very Urgent.. - JSP-Servlet
Program Very Urgent..  Respected Sir/Madam, I am R.Ragavendran.... reference. http://www.roseindia.net/jsp/popup-window-using-ajax-in-jsp.shtml... its most urgent.. Thanks/Regards, R.Ragavendran..   Hi friend
courier management service (using servlets,jsp,jdbc)
courier management service (using servlets,jsp,jdbc)   is anyone having information about courier management service ? plz share it .its urgent THANKING YOU IN ADVANCE
Help on JSP and JDBC - JDBC
Help on JSP and JDBC  Retrieve data from Database in JSP and JDBC... for connection from that class get values. jsp only for view , even html designers can...;% Connection con = null; String url = "jdbc:mysql://localhost:3306/"
JSP and AJAX very urgent - Ajax
JSP and AJAX very urgent  Hi Team, This is Ragavendran.R.. I have a very basic doubt in AJAX. While Using AJAX, of course, there will be tag involved in JSP page. But in my current project, I am using too many tags
Servlet and Jsp - JDBC
Servlet and Jsp  Hai I need a program to update the table records ......The program should have only update code.....It shouldnot combine with Add or delete code. It is very urgent ... Send me the full code
Servlets and Jsp - JDBC
and Jsp.It is very urgent ,please send the program
JSP and JDBC - JSP-Servlet
JSP and JDBC  Respected sir/Madam, I am R.Ragavendran.. I am in urgent need of programming from roseindia team.. My requirement... for JDBC codings must be present.. NOTE: When User clicks Insert,for example
servlets And Jsp - JDBC
me.It is very urgent .I tried but i couldn get it properly.  Hi Friend, Your problem is not very clear to us so could you please clarify it to us
its very urgent please help me
its very urgent please help me  how can i retrieve all images from ms access database and display in jsp pages
Ple help me its very urgent
Ple help me its very urgent  Hi.. I have one string 1)'2,3,4' i want do like this '2','3','4' ple help me very urgent
Help on JSP - JDBC
and Enquiry system. I had completed the front end design with the help of html,delete and search the database from the html file with the help of JSP.  hi...;jdbc:oracle:[email protected]:1521:xe","scot","tiger"
&nbsp;(very urgent) - Design concepts & design patterns
 (very urgent)  hi friends, This is my code in html                   
Displaying Date in jsp - JDBC
in a database.i am getting input value from HTML and i use jsp application to interact with database.My JSP code for inserting Date is below: String dateStr... ----------------------------------------- Read for more information. http://www.roseindia.net/jsp/ Thanks
Servlet and Jsp - JDBC
code of this. It is very urgent.Thanks in advance
very urgent - Design concepts & design patterns
very urgent  Hi friends, I have a page layout with a menu on the left, the menu looks perfect in my personal system but the spacing and the rollover... control over the CSS not the HTML itself Thanks in advance.Give me solution
very urgent, want to submit my project on monday
very urgent, want to submit my project on monday  i have the code for connected combo-boxes(jsp). But the thing i want to know is, how to access the values selected in those combo-boxes, for storing in database. in the case
very urgent - Java Server Faces Questions
check it once and give me a correct solution. It is very urgent for me. Thanks...very urgent  Hi sir, yesterday i send total my code to find where i have done mistake ,you send a reply for that also but in that you told remove
very urgent - Java Server Faces Questions
very urgent  Hi sir, see my code and please tell me mistake. it is very urgent for me. here is my code: addmin.jsp: Users... [email protected] 8888 deepak kumar It is very urgent for me please give
Basic problem but very urgent - JSP-Servlet
Basic problem but very urgent  Respected Sir/Madam, I am... kind reference. http://www.roseindia.net/jsp/popup-window-using-ajax... me the cause of the problem asap because its most urgent.. Thanks/Regards

Ads

 
Advertisement null

Ads