Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Fresher Job


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

JSP
Expert:Ragavendran.R
Respected sir/Madam,
I am R.Ragavendran. I am In a very very urgent need of a program. Actually I have done it 50% and for the rest, I need your kind help.The Requirement is as follows:
1) My HTML Page must consist of a combo box or list box which includes all the employee iD's present in the database. The ID present in the List box, when clicked, must fit into the Employee ID text Box automatically along with the detail of employee name for which I have provided another text box when query operation is submitted.
Here is the code:
FindEmployee.html:
<HTML>
<BODY BGCOLOR="LIGHTYELLOW">
<FORM METHOD="POST" 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" NAME="id"> </FONT> </TD>
</TR>
<TR>
<TD> <FONT SIZE=5> Enter Employee Name </TD>
<TD><INPUT TYPE="TEXT" 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> <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>
</FORM>
</BODY>
</HTML>

Process.jsp:
<%@ page language="java" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.sql.*" %>
<HTML>
<BODY bgcolor="LIGHTYELLOW">
<FORM NAME="f1" ACTION="FindEmployee.html">
<%
String str=request.getParameter("r1");
String sessionValue="";
try {
if(str.equals("add")) {
String name=request.getParameter("name");
String code=request.getParameter("id");
int EmpID=Integer.parseInt(code);
String Inserted;
try {
String que="INSERT INTO employee (Emp_code,Emp_name) VALUES("+EmpID+",'"+name+"')";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:Employee","","");
Statement stmt=null;
stmt=con.createStatement();
int ins=stmt.executeUpdate(que);
session.setAttribute("status","Inserted");
sessionValue=(String)session.getAttribute("status");
if(sessionValue.equals("Inserted")) {
%>
<script language="javascript">
alert("Insertion successful");
document.location="FindEmployee.html";
</script>
<%
}
con.commit();
stmt.close();
con.close();
}

catch(Exception e) {
out.println(e.toString());
}
}
%>
<%
if(str.equals("del")) {
String name=request.getParameter("name");
String code=request.getParameter("id");
int EmpID=Integer.parseInt(code);
String Deleted;
try {
String rem="DELETE Emp_code,Emp_name FROM Employee where Emp_code=?";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:Employee","","");
PreparedStatement stmt=null;
stmt=con.prepareStatement(rem);
stmt.setInt(1,EmpID);
int erase=stmt.executeUpdate();
if(erase==0) {
%>
<script language="javascript">
alert("This Emp ID Not found");
document.location="FindEmployee.html";
</script>
<%
}
if(erase==1) {
%>
<script language="javascript">
alert("Deletion Successful");
document.location="FindEmployee.html";
</script>

<%

}
con.commit();
stmt.close();
con.close();
}
catch(Exception e) {
out.println(e.toString());
}
}
%>
<%
if(str.equals("mod")) {
String rep=request.getParameter("nname");
String code=(String)request.getParameter("id");
int ID=Integer.parseInt(code);
try {
String rec="UPDATE Employee SET Emp_name='"+rep+"' where Emp_code='"+ID+"'";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:Employee","","");
Statement stmt=null;
stmt=con.createStatement();
int mod=stmt.executeUpdate(rec);
if(mod==0) {
%>
<script language="javascript">
alert("This Emp ID Not found");
document.location="FindEmployee.html";
</script>
<%
}
if(mod==1) {
%>
<script language="javascript">
alert("Record updated successfully");
document.location="FindEmployee.html";
</script>
<%
}
con.commit();
stmt.close();
con.close();
}
catch(Exception e) {
out.println(e.toString());
}
}
}
catch(NumberFormatException ne) {
%>
<script language="javascript">
alert("Please Enter a Valid ID");
document.location="FindEmployee.html";
</script>
<%
}
catch(NullPointerException nu) {
%>
<script language="javascript">
alert("Invalid Request. Please Try Again.");
document.location="FindEmployee.html";
</script>
<%
}
%>
I NEED THE CODING FOR QUERY HERE WHEN COMBO BOX IS CLICKED
if(str.equals("query"))
{
YOUR CODE PLZ


Thank You/Regards,
R.Ragavendran..
</FORM>
</BODY>
</HTML>



Answers
Dear Raghavendran,
Your wrote the code in clumsy way. To fullfill your requirement , it is not possible to do like this. Tell me your requirements clearly. I will give you complete code which satisfies your requirements.

Onething i want to tell u regarding ur problem. It is not possible to dynamically populate the data in a html form. It must be jsp. Because, html is static where as jsp is dynamic.


More Questions
Post Answers
 
Ask Question Facing Programming Problem?
Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.