problem in record viewing in jsp

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









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
sort a record in jsp - JSP-Servlet
sort a record in jsp  hello, can i get a code that displays 10... it displays the next 10 pages and so on. Im using jsp and mysql database. thx priya...: Pagination of JSP page Roll No Name Marks Grade
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
viewing the ms word in print layout from jsp - Java Beginners
viewing the ms word in print layout from jsp  Hi all, I am trying to export ms word from jsp in print layout format.I used the code for converting into ms word but it is opening in web layout. My requirement
JSP Problem - JSP-Servlet
JSP Problem  Hi, I have problem,this is my senario I have one jsp,this jsp having the 3 fields.let me take 3fields userName,emailAddress... for more information, http://www.roseindia.net/jsp Thanks
jsp problem - JSP-Servlet
jsp problem  here is a code for Retrieving image from mysql database through jsp. but i cann't set size of image when it was display so what should... working but my problem is size of image. so can u just help?? code
jsp problem - JSP-Servlet
jsp problem  here is a code for Retrieving image from mysql database through jsp. but i cann't set size of image when it was display so what should... working but my problem is size of image. so can u just help?? code
jsp problem - JSP-Servlet
jsp problem  hi, i am working on a project of developing a shopping cart for online book store.can it be done using jsp?if yes, can u please help me doing so?  Hi Friend, Please visit the following link: http
coding problem - JSP-Servlet
coding problem  dear sir i m very new to JSP sir i m getting problem...) .and after that option being selected for that the record from the databse should... that record from the database where asian paints found and other combobox dynamically
problem in jsp programming - JSP-Servlet
problem in jsp programming  Write a JSP program which displays a webpage containing arrival of new items within a particular month in the different... in solving the problem : Connection with mysql database
coding problem - JSP-Servlet
coding problem  dear sir will u plz tell me how can we delete a record from the database(MSaccess) when option in the combobox is selected(jsp)  If u want to delete the record from database, by seleting
problem in programming - JSP-Servlet
problem in programming  Hi! I am new with jsp. I am facing a problem in programming to calculate the time interval between login time and logout time of user
jsp code problem - JSP-Servlet
jsp code problem  Hi, I have employee details form in jsp. After... have a problem with open the next form. plz, help me. thanks,  Hi.... http://www.roseindia.net/jsp/ Thanks
Session Problem in JSP - JSP-Servlet
Session Problem in JSP  I have developed a online feedback form in JSP platform. I have created normal session in JSP page. It is running in my... normally from Remote machine by only writing JSP code.  Hi friend
jsp code problem - Java Beginners
jsp code problem  Hi, I have a problem with else part. It did not show the message box when the result set is null. plz, help me. thank u..."); regards, sakthi   Hi friend, You want if no record in database
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
jsp usebean problem - Struts
popupwindow jsp below code run.. ...here iam getting the problem..in the below...jsp usebean problem   --Select... jsp
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
logout problem?? - JSP-Servlet
logout problem??  sir, the logout code which u have send is not the proper solution coz,by using this code the browser get closed which shuold.../Logout.shtml http://www.roseindia.net/jsp/loginstatus.shtml Thanks
jsp image problem - JSP-Servlet
jsp image problem  hi everyone, How to display multiple images from mysql database to jsp page. please help me
logout problem.. - JSP-Servlet
logout problem..  hi... first of all thanks for ur... but their is some problem with the the logout,i m not able to logout when... done in the code i have used session object in project's servlet and jsp
Array problem - JSP-Servlet
.. Bur my problem is that if the pop up window contains only 1 record
JSP code problem - JSP-Servlet
JSP code problem  Hi friends, I used the following code...: <% //to get the content type information from JSP... of: Please can somebody rectify this problem........  
Jsp Code Problem - JSP-Servlet
Jsp Code Problem  I use DocType in my Jsp Page. The Links are not functioned after Applying the DocType. Could you tell me any way to activate the link. Thank You.   Hi Friend, Please send your code. Thanks
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
jsp code problem - JSP-Servlet
jsp code problem  i want to make the bill from the barcode. how do i convert a barcode into a decimal number
Jsp ,Servlet Problem - JSP-Servlet
Jsp ,Servlet Problem  hi, m new to jsp n Servlet. i really find ur tricks very effective.Last time u had helped me to connect my java program with oracle. it worked wonders. now i m starting jsp n servlet learning.. pls
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
Java Problem - JSP-Servlet
Java Problem  How to run a Simple JSP program ? what steps... the webapps folder of apache tomcat. 5)Create a jsp file 'hello.jsp'.You can put your jsp file either inside the web application folder along with WEB-INF or you
jsp code problem - JSP-Servlet
jsp code problem  hi, I am going to execute the following code which has been given your jsp tutorial. retrive_image.jsp: but while I...) org.apache.jsp.retriveimage_jsp._jspService(retriveimage_jsp.java:115
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
tomcat problem - JSP-Servlet
perfectly. Kindly let me know what is the problem at an earliest. Thanking... found your problem.. http://www.roseindia.net/web-application-server/tomcat
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
Statistical charts in JSP - problem
Statistical charts in JSP - problem  hey! i get this error when i run... to compile class for JSP: An error occurred at line: 9 in the generated.... org.jfree.data.jdbc.JDBCCategoryDataset resolves to a package An error occurred at line: 11 in the jsp
Jsp include page problem
Jsp include page problem  I have included footer.jsp in all my pages. It is working in all pages except search.jsp. In search.jsp (Old footer.jsp content is displayed ) How can I rectify this?   Hi, You have to delete
resultset problem - JSP-Servlet
resultset problem  hi I have one problem with resultset? ResultSet rs=st.execute("select subjname,staffname from staffdetails"); while(rs.next()) { st.executeUpdate("update CSEFIRSTYEARTIMETABLE set p2
coding problem - JSP-Servlet
coding problem  Dear sir i m very new to JSP .I am using two conbobox .if any option is selected in first combobox then only its data from the database should be displayed in other combobox, means how can we refresh
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
Problem in inserting clob data in jsp
Problem in inserting clob data in jsp  how to insert any rich text editor data (which have more than 32766 characters) in a clob type column of oracle database with jsp

Ads