Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet JSP,JDBC and HTML(Very Urgent)
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ragavendran.R
JSP,JDBC and HTML(Very Urgent)
1 Answer(s)      6 years and 4 months ago
Posted in : JSP-Servlet



Advertisement
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
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
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
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
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
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
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
&nbsp;(very urgent) - Design concepts & design patterns
 (very urgent)  hi friends, This is my code in 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
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 - 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
Query regarding JSP, JDBC
Query regarding JSP, JDBC  can I get the code for the question asked by me regarding JSP,JDBC
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... deepak@roseindia.net 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
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 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
 

 

 

DMCA.com