JSP,JDBC and HTML(Very Urgent)

JSP,JDBC and HTML(Very Urgent)

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









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
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
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
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
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
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/"
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
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
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
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
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
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:thin@localhost:1521:xe","scot","tiger"
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
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
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
&nbsp;(very urgent) - Design concepts & design patterns
 (very urgent)  hi friends, This is my code in html                   
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
JSP-jdbc validation - JSP-Servlet
JSP-jdbc validation  How to validate login email id using JSP, where..., login application in jsp function validateForm(theForm... for more information. http://www.roseindia.net/jsp/valid-email
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
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
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
Programming help Very Urgent - JSP-Servlet
Please please its very urgent.. Thanks/Regards, R.Ragavendran..  Hi friend, Read for more information, http://www.roseindia.net/jsp...Programming help Very Urgent  Respected Sir/Madam, Actually my code
Popup very urgent plz - JSP-Servlet
Popup very urgent plz  Respected Sir/Madam, I am R.Ragavendran.. I got your reply.. Thank you very much for the response. Now I am sending the code...='' Its Very Urgent.. Please send me the coding asap.. Thanks/Regards
&nbsp;(very urgent) - Java Server Faces Questions
 (very urgent)  hi friends, This is my code in JSF                    
Radio Buttons in DB Very Urgent - JSP-Servlet
Very Urgent.. Please send...Radio Buttons in DB Very Urgent  Respected Sir/Madam, I am R.Ragavendran.. I got your reply.. Thank you very much for the response. Now I am sending
Validating Number Very Urgent - JSP-Servlet
Validating Number Very Urgent  Respected Sir/Madam, I am...('id').value= document.getElementById('name').value='' Its Very Urgent.. Please send me the coding asap.. Thanks/Regards, R.Ragavendran.. 
Simple Program Very Urgent.. - JSP-Servlet
Simple Program Very Urgent..  Respected Sir/Madam, I am... database using JDBC Database. Please send me the modified coding asap because its most urgent.. Thanks/Regards, R.Ragavendran..  
Very urgent Image Selection - JSP-Servlet
Very urgent Image Selection  Respected Sir/Madam, I am R.Ragavendran.. If you are telling that your coding works fine, then can u plz tell me or send me the output of the following code asap? var imageURL
Please help me... its very urgent
Please help me... its very urgent  Please send me a java code to check whether INNODB is installed in mysql... If it is there, then we need to calculate the number of disks used by mysql
plz help -java project very urgent
plz help -java project very urgent  ? Ford furniture is a local furniture store in acts, and they as CS graduate students to implement a software system to generate various reports for them at the end of each month. You
Simple problem Very Urgent - JSP-Servlet
Simple problem Very Urgent  Respected SDir/Madam, I am R.ragavendran.. Thanks for your superb reply. I got the coding. But I find a simple problem which i hava tried my level best to solve. A pop up window is opening
jsp - JDBC
jsp - JDBC
variable. JSP Page... Login SuccessfulADS_TO_REPLACE_1 <%-- <jsp:forward page...)action.jsp: JSP Page Hello Login SuccessfulADS_TO_REPLACE_2 Login
jsp - JDBC
jsp  how to link jsp code with next htmlcode.  Hi keerthi, Can u explain ur question clearly? What is your exact Requirement
jsp - JDBC
: Unable to compile class for JSP An error occurred at line: 20 in the jsp file...\localhost\Airlines-Project\org\apache\jsp\Flightdetails_jsp.java:69: cannot find symbol symbol : variable src location: class org.apache.jsp.Flightdetails_jsp
jsp - JDBC
about update at http://www.roseindia.net/jsp/implement-javascript
JSP - JDBC
JSP Store Results in Integer Format  JSP Example Code that stores the result in integer format in JSP  Hi! Just run the given JSP Example...;/b></td><% Connection con = null; String url = "jdbc:mysql
jsp - JDBC
jsp  I have one jsp code.but it is included oracle databse...("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager.getConnection("jdbc:oracle... = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle","scott","tiger"); I
jsp - JDBC

Ads