sivasakthi
problem in record viewing in jsp
0 Answer(s)      5 years and 5 months ago
Posted in : JSP-Servlet
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();
}
}

}
Advertisement
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
viewing
viewing  viewing from session and display e-ticket using struts
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
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
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
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
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 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
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
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
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
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
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
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
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
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
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
Record user login and logout timing In JSP
Record user login and logout timing In JSP       In this section, we have developed a web application of maintain record of the user Login and Logout Time  in JSP
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
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
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