problem in record viewing in jsp

Ads
 

problem in record viewing in jsp

hai i send the code can you please find where is the problem it is not showing any error but i cannot able to view the record after eclipse ide is closed and reopen it
i have used the jsp and servlet and back end mysql
actually what is my problem is i have to everytime refresh the viewing record link i.e Click here to view all the records link in Doctor.jsp page in that everytime DoctorView.jsp like that i have to rewrite it means it is showing the record but after sometime it is not showing the record so once again i have to rewrite the jsp page link.

please reply me today itself for my problem.
i have to finish it today.
i dont know what is the problem and what is happening
this is my code
doctor.jsp
<%@page import="java.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style>
.tdcls{
font-weight:bold;
}
A:visited {color: #00000;font-weight:bold; text-decoration: underline}
A:link {color: #FFC0C0; text-decoration: none}
A:active {color: #C0FFC0; text-decoration: none}
A:hover { color: #FF0000; text-decoration: none}
</style>
<script>
function validate()
{

if(document.frm.first_name.value=="")
{
alert("Please enter first name");
document.frm.first_name.focus();
return false;
}
if(document.frm.last_name.value=="")
{
alert("Please enter last name");
document.frm.last_name.focus();
return false;
}

return true;

}
</script>

<script Language="JavaScript">
function validatecombo(){
var selectedCombobox=(frm.sex.value);
if (selectedCombobox=="0") {
alert("Please Select Sex");
return false;
}
var selectedCombobox=(frm.grade.value);
if (selectedCombobox=="0") {
alert("Please Select Grade");
return false;
}

return true;
}
</script>





<script language = "Javascript">

function emailcheck(str) {

var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail ID")
return false
}

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail ID")
return false
}

if (str.indexOf(" ")!=-1){
alert("Invalid E-mail ID")
return false
}
alert("valid E-mail ID")
return true
}

function ValidateEmail(){
var emailID=document.frm.e_mail

if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email Address")
emailID.focus()
return false
}
if (emailcheck(emailID.value)==false){
emailID.value=""
emailID.focus()
return false
}
return true
}
</script>







</HEAD>

<BODY background="E:\projects\java\Employee\toothimg.bmp">
<br><br>

<form name="frm" action="http://localhost:8080/Employee/Doctor" method="post" onSubmit="return validate(),validatecombo(),ValidateEmail();">
<%
String doc_id = "";
String first_name = "";
String last_name = "";

String sex = "";
String grade = "";
String e_mail = "";
String readonly="";
String bttn_value="Add";



if(request.getParameter("doc_id")!=null && request.getParameter("doc_id")!="")
{
doc_id= request.getParameter("doc_id").toString();

readonly = "readonly";
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "dentist";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "admin";
bttn_value = "Update";

Statement st;


try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");

String query2 = "SELECT * from doctor_details where doc_id='"+doc_id+"'";


st = conn.createStatement();




ResultSet rs2 = st.executeQuery(query2);

while(rs2.next())
{
first_name = rs2.getString(2);
last_name = rs2.getString(3);
sex=rs2.getString(4);
grade=rs2.getString(5);
e_mail=rs2.getString(6);

}

}

catch (Exception e) {
e.printStackTrace();
}

}

%>

<table cellpadding=5 cellspacing=3 border=0>

<th colspan=2>
<font size=5 color="#DB70DB">Doctor Details</font>
<br><font size=1></font>
</th>
<br>
<br>

<tr><td class="tdcls">First Name</td><td><input type="text" name="first_name" value="<%=first_name%>"></td></tr>
<tr><td class="tdcls">Last Name</td><td><input type="text" name="last_name" value="<%=last_name%>"></td></tr>

<tr><td class="tdcls">Sex</td>
<td><select name="sex">

<option value=0>------Select------</option>
<option value="Male" <% if(sex.equals("Male"))out.println("selected");%>>Male</option>
<option value="Female" <% if(sex.equals("Female"))out.println("selected");%>>Female</option>
</select>
</td></tr>

<tr><td class="tdcls">Grade</td>
<td><select name="grade">
<option value=0>------Select------</option>

<option value="A" <% if(grade.equals("A"))out.println("selected");%>>A</option>
<option value="B" <% if(grade.equals("B"))out.println("selected");%>>B</option>
</select>
</td></tr>


<tr><td class="tdcls">Email</td><td><input type="text" name="e_mail" value="<%=e_mail%>"></td></tr>

<tr><td colspan=2 align="center"><input type="submit" name="submit" value="<%=bttn_value%>">
<input type="reset" value="Reset"></td></tr>
</table>
<br><br>
<%
if(!(request.getParameter("doc_id")!=null && request.getParameter("doc_id")!=""));


%>
<table width="100%" align="center">
<tr><td align="center"><input type=button value="Back" onCLick="history.back()">
</td></tr>
</table>



<table width="100%" align="center">
<tr><td align="center"><a href="http://localhost:8080/Employee/DoctorView.jsp">Click here To show all records</a></td></tr>
</table>

<table width="100%" align="left">
<tr><td align="center"><a href="http://localhost:8080/Employee/DoctorPatient.jsp">View Appointment</a></td></tr>
</table>






<%

%>

</BODY>
</HTML>
doctor.java
package myservlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.PreparedStatement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class Nurse
*/
public class Doctor extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public Doctor() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/

public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{

doGet(request , response );

}


public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{

response.setContentType("text/html");
PrintWriter out = response.getWriter();

System.out.println("MySQL Connect Example.");
Connection conn = null;
Object PreparedStatement =null;

String url = "jdbc:mysql://localhost:3306/";
String dbName = "dentist";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "admin";


String doc_id = request.getParameter("doc_id");
String first_name = request.getParameter("first_name");
String last_name = request.getParameter("last_name");
String sex = request.getParameter("sex");
String grade = request.getParameter("grade");
String e_mail = request.getParameter("e_mail");
String bttn_value = request.getParameter("submit");


Statement st;

try {

java.util.Date date = new java.util.Date();
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");

int i=0;
if(bttn_value.equals("Add"))
{
String query_1 = "insert into doctor_details set first_name='"+first_name+"',last_name='"+last_name+"',sex='"+sex+"',grade='"+grade+"',e_mail='"+e_mail+"'";
out.println("query_1 " + query_1);
out.println("<br>");
st = conn.createStatement();
i = st.executeUpdate(query_1);
out.println("<br>");
out.println("i " + i);

response.sendRedirect("http://localhost:8080/Employee/Doctor.jsp");
}
else if(bttn_value.equals("Update"))
{


String query_1 = "update doctor_details set first_name='"+first_name+"',last_name='"+last_name+"' ,sex='"+sex+"',grade='"+grade+"',e_mail='"+e_mail+"'where doc_id='"+doc_id+"'";
out.println("query_1 " + query_1);
out.println("<br>");
st = conn.createStatement();
i = st.executeUpdate(query_1);
out.println("<br>");
out.println("i " + i);

response.sendRedirect("http://localhost:8080/Employee/Doctor.jsp");
}











// pw.println(query1);
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
response.sendRedirect("DoctorView");
e.printStackTrace();
}
}
}
DoctorView.jsp
<%@page import="java.util.*"%>
<html>

<head>
<title>Doctor Details form</title>
<style>
A:visited {color: #00000;font-weight:bold; text-decoration: underline}
A:link {color: #FFC0C0; text-decoration: none}
A:active {color: #C0FFC0; text-decoration: none}
A:hover { color: #FF0000; text-decoration: none}
.loginhead1{
text-align:left;
padding-left:5px;
}
</style>
</head>

<body>
<center>
<table border="1" width="800px" cellspacing="0" cellpadding="0" bgcolor="bluelight">
<tr>
<td width="10%" class="loginhead1" align="center"><b>ID</b></td>
<td width="10%" class="loginhead1" align="center"><b>FirstName</b></td>
<td width="19%" class="loginhead1" align="center"><b>LastName</b></td>
<td width="19%" class="loginhead1" align="center"><b>Sex</b></td>
<td width="19%" class="loginhead1" align="center"><b>Grade</b></td>

<td width="14%" class="loginhead1" align="center"><b>Update</b></td>
<td width="14%" class="loginhead1" align="center"><b>Delete</b></td>

</tr>
<%
//String ename="";



ArrayList arList=null;
ArrayList AdminPendrequest = (ArrayList)session.getAttribute("arDataList");
//out.println(AdminPendrequest);
out.println("<br>");
int count=0;

if(AdminPendrequest!= null){
for(int i=0;i<AdminPendrequest.size();i++)
{
count++;
arList = (ArrayList)AdminPendrequest.get(i);


String doc_id =arList.get(0).toString();
String first_name = arList.get(1).toString();
String last_name = arList.get(2).toString();

String sex = arList.get(3).toString();
String grade = arList.get(4).toString();
//String e_mail = arList.get(5).toString();
//String date_of_joining = arList.get(6).toString();
//ename = first_name+ " " + last_name;



%>

<tr>
<form name="frm" method="post" action="Doctor.jsp">

<input type="hidden" name="doc_id" value="<%=doc_id%>">

<td width="10%" class="loginhead1" align="center"><%=doc_id%></td>
<td width="10%" class="loginhead1" align="center"><%=first_name%></td>
<td width="10%" class="loginhead1" align="center"><%=last_name%></td>
<td width="10%" class="loginhead1" align="center"><%=sex%></td>
<td width="10%" class="loginhead1" align="center"><%=grade%></td>

<td width="19%" class="loginhead1" align="center"><input type="submit" name="submit" value="Update"></input></td>
<td width="19%" class="loginhead1" align="center"><a href='http://localhost:8080/Employee/DeleteRecord'>Delete
</a>
<%

%>

</tr>
</form>
<%
}

}
%>


</table>
<br>
<br>


<table width="100%" align="center">
<tr><td align="center"><input type=button value="Back" onCLick="history.back()">
</td></tr>
</table>




<table>
<tr><td align="center"><a href="Doctor.jsp">Add More Doctor</a></td></tr>
</table>

</center>


<table width="100%" align="center">
<tr><td align="center"><a href='http://localhost:8080/Employee/Adminhome.jsp'><font size=4">Home
</a></font></td></tr>
</table>
</body>

</html>

DoctorView.java
package myservlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
* Servlet implementation class DoctorView
*/
public class DoctorView extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public DoctorView() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();

System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "dentist";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "admin";

Statement st;
ArrayList arData=null;
ArrayList arDataList=new ArrayList();
HttpSession session=request.getSession(true);
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
String query = "SELECT *from doctor_details";

st = conn.createStatement();

ResultSet rs = st.executeQuery(query);

while(rs.next())
{
arData=new ArrayList();

arData.add(rs.getInt(1));
arData.add(rs.getString(2));
arData.add(rs.getString(3));
arData.add(rs.getString(4));
arData.add(rs.getString(5));




arDataList.add(arData);
}

pw.println("query4 " + query);
pw.println("<br>");

session.setAttribute("arDataList",arDataList);
pw.println("arData " + arData);
pw.println("<br>");
pw.println("arDataList " + arDataList);
pw.println("<br>");
pw.println("session "+ session.getAttribute("arDataList"));
pw.println("<br>");
response.sendRedirect("DoctorView");



pw.println(query);
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
response.sendRedirect("DoctorView");
e.printStackTrace();
}
}

}
View Answers

Ads









Related Tutorials/Questions & Answers:
Problem in record viewing in jsp - JSP-Servlet
Problem in record viewing in jsp  hai i have developed the application using jsp,servlets in eclipse ide i have to insert,delete,update and view... i have link like this for viewing the record. Click here To show all records
problem in record viewing in jsp - JSP-Servlet
problem in record viewing in jsp  hai i send the code can you please... the record after eclipse ide is closed and reopen it i have used the jsp... refresh the viewing record link i.e Click here to view all the records link
Advertisements
problem in viewing the mail's content using javamail
problem in viewing the mail's content using javamail  i'm using the following code to view a mail in a javamail application problem i'm facing is if there are any attachments of .txt format they are also displayed
viewing
viewing  viewing from session and display e-ticket using struts
Jsp code for disabling record.
Jsp code for disabling record.  I want a Jsp and servlet code for the mentioned scenario. Q. A cross sign appears in front of each record, click to disable the record.System marks the record as disabled.The record
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table..." action="http://localhost:8080/examples/jsp/insertdata.jsp"> <table> <
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table..." action="http://localhost:8080/examples/jsp/insertdata.jsp"> <table> <
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table..." action="http://localhost:8080/examples/jsp/insertdata.jsp"> <table> <
Jsp problem
Jsp problem  Hello friends.I want to share my jsp problem.I want to show all of my database(mysql) tables except two(user,manufacturer) in a jsp page.plssss help me
jsp problem
jsp problem  problem:::::::: On JSP form ,when i insert data in text field........at that time action is perform and data is retriev from data base and get assign to other field on that form........ when data is assign to other
jsp problem
jsp problem  Hello Friends, I want to show one page for 5 seconds and after that i want to redirect the page to another URL
jsp problem
jsp problem  Hi every one plz give me answer for below question ASAP I created one JSP(used pre defined javascript in jsp to get rtf format in browser) which creats RTF Format in browser to enter data. MY question is after i
jsp reload current page problem
jsp reload current page problem  Hi, i am facing problem while reloading the JSP page
jsp reload current page problem
jsp reload current page problem  Hi, i am facing problem while reloading the JSP page
JSP code problem - JSP-Servlet
JSP code problem  HI.. I have a DB2 stored procedure wich return a result set. I have made a report basing on this procedure using Crystal Reports. How to pass parameters to this procedure with java code in a JSP page
Loading a jsp page (with record from database) from another jsp page
Loading a jsp page (with record from database) from another jsp page  Suppose I have two jsp pages Search.jsp and Getdata.jsp. There are two fields... as Getdata.jsp will be loaded, it will show the first record. How can I do
Radio Button Problem in jsp.
Radio Button Problem in jsp.  I have a small doubt in my application, my requirement is to get a "single selectible row", I generated a radio button... radio button values from jsp to action using javascript
Statistical charts in JSP - problem
Statistical charts in JSP - problem  hey! i get this error when i run... org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred... An error occurred at line: 11 in the jsp file: /BarChart.jsp
JSP run problem
JSP run problem  type Exception report message description... this request. exception org.apache.jasper.JasperException: Exception in JSP...) root cause java.lang.NullPointerException org.apache.jsp.bb_jsp
jsp and bean problem
jsp and bean problem  Hi i have the following jsp code... Can you plz help me in separating the code to bean? I'm new to bean and need it for my project...Plz help...Its quite urgent... Regards Priya <%@ page import
JSP Delete Record From Table Using MySQL
JSP Delete Record From Table Using MySQL This tutorial explains you that how to write a JSP for deleting a record from database table. In this section you.... In this tutorial you will learn that how to delete a record of a database table in JSP
Uploading Excel sheet record in JSP to insert data in MySql
Uploading Excel sheet record in JSP to insert data in MySql  Need Help how to upload Excel (.xls) file and insert data in Mysql using JSP it wil be wonder for me if any help me
fetch record from oracle database using jsp-servlet?
fetch record from oracle database using jsp-servlet?  how can i fetch data from oracle database by using jsp-servlet. i'm using eclipse, tomcat server and oracle database and creating jsp pages and also using servlet
problem in jsp using ms-access
problem in jsp using ms-access  after starting server(tomcat) wen v...)Your DSN will get created. 6) Restart your server and run your jsp code. Here... will get created. 6) Restart your server and run your jsp code. Here is your
JSP - Problem of displaying result at webpage
JSP - Problem of displaying result at webpage  Can anyone please help to solve my problem below. My webpage has problem in displaying result position. The result should be display below my title. How do i solve it? Thank you so
How to add a column with checkboxes for each record in my table in JSP
How to add a column with checkboxes for each record in my table in JSP   Hi, Could you please explain it to me how I can add a column with check boxes for each record in my table in JSP? Also, I want to figure out a way
Java Servlet Problem - JSP-Servlet
method. Please help!!  Hi friend, Please explain problem in details for complete solution and send code the where are you problem. Thanks
problem at the time of execution - JSP-Servlet
problem at the time of execution  when i was running web applications the exception i.e 404 resource is not available what it means and where it occures what is the solution   Hi Friend, This error occurs when
How i upload file and save that record in database using JSP?
How i upload file and save that record in database using JSP?  Hi All, I m the beginner in JSP and I want to upload the file and store that file and some other form data in MySQL database. Ex. There is one employee detail form
problem on jsp, inserting data into table(mysql).
problem on jsp, inserting data into table(mysql).  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table name also is given by the user.My database
Jsp/java-script, spring combination problem
Jsp/java-script, spring combination problem   Hi Friends....... I am developing one application using jsp,spring,java script,hibernate,Pojo There is one Jsp form on that I want data as location and ward wise; There is two

Ads