Home Answers Viewqa JSP-Servlet JSP Servlet update patient data

 
 


john
JSP Servlet update patient data
0 Answer(s)      3 years ago
Posted in : JSP-Servlet

Hi Friend,

I'm attaching my inserting patient data servlet as requested. I tried your posted code, its not working in my case, perhaps of the following things which I can explain to you so it is clearer.

1. I am doing a search on a patient visit table which has a FK on patient id, but there can be many visits by the same customer, right? meaning this id is repeated in the search results, however usually a patient will have only one visit on a particular date, so I decided that I will edit based on date of visit.which works fine but when I go to popup.jsp, I need to have the id as well because editing can be only done when you have in the where clause 'where patient_id='"+id+"' and dov='"+date+"'; if i use any other statement obviously there will be mutliple forms popping up on the edit window and that is not the desired result if you know what i mean, I need the particular one.

So with your code, I am getting the edit page but blank maybe because...
1. you have converted the date into 'mm-dd-yyyy' or 'dd-mm-yyyy' format where as my stored date is 'yyyymmdd' so right now in the URL, I am getting undefined=undefined-undefined

2. My index page has a patient register form and also the search facility on the same page, but this one is already resolved because I am doing it only based on id from your previous code. However, the issue or response Send Redirect so that the data from the form doesn't disappear which I requested last time.

3. Also, if you see my servlet code, you can see I am populating 2 tables based on a single form which works fine. but I cannot seem to get the fields populate in the edit process using the one while (rs.next()){ loop. Can you show me how to populate the rest of the fields from a different table? And finally, if my search result from the database returns no records based on the search criteria, I want a message "no records found' i tried many ways like while (rs.next()){ int count=0; ... count++;...if(count>0){ message"no records found'} but its not working, can you please show me how this can be done? Thank you so much for all your help.
Regards,

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.swing.*;

public class registeration extends HttpServlet{
@Override
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
/**Process the HTTP Get request*/
@Override
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
String connectionURL = "jdbc:mysql://localhost:3306/patient_db";
Connection connection=null;
ResultSet rs;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String message_update="Data has been successfully inserted!";
String title="Update Message";
String error_message="Error Message ";



//get the variables entered in the form (patient table)
String patient_id = req.getParameter("pid");//not null, unique
String fname = req.getParameter("f_name");
String minitial = req.getParameter("m_initial");
String lname = req.getParameter("l_name");//not null
String gender =req.getParameter ("gender");//select option
String dateofbirth = req.getParameter("dob");//not null
String status = req.getParameter ("status");//select option
String hphone = req.getParameter ("hphone");
String wphone = req.getParameter ("wphone");//not null
String mphone = req.getParameter ("mphone");
String email = req.getParameter ("email");
String occupation = req.getParameter ("occupation");
String checkValues1[]=req.getParameterValues("region");//select list
String address = req.getParameter ("address");
String checkValues2[]=req.getParameterValues("bloodgrp");//select list
//String notes = req.getParameter ("notes");
//String picture = req.getParameter ("picture");

//Get Form Variables - Insurance Table columns

String checkValues3[]=req.getParameterValues("insurancec");//not null(select list)
String policynum = req.getParameter ("policynum");
String smoker = req.getParameter ("smoker");
String referredto = req.getParameter ("referredto");



try {
// Load the database driver
Class.forName("com.mysql.jdbc.Driver");
// Get a Connection to the database
connection = DriverManager.getConnection(connectionURL, "root", "root");

String value1="";
for(int i=0;i<checkValues1.length;i++){
value1+=checkValues1[i]+" ";
}
String value2="";
for(int i=0;i<checkValues2.length;i++){
value2+=checkValues2[i]+" ";
}
String value3="";
for(int i=0;i<checkValues3.length;i++){
value3+=checkValues3[i]+" ";
}



//Add the data into the patient table
String sql = "insert into patient values (?,?,?,?,?,STR_TO_DATE(?,'%m/%d/%Y'),?,?,?,?,?,?,?,?,?)";
PreparedStatement pst = connection.prepareStatement(sql);
pst.setString(1, patient_id);
pst.setString(2, fname);
pst.setString(3, minitial);
pst.setString(4, lname);
pst.setString(5, gender);
pst.setString(6,dateofbirth);
pst.setString(7, status);
pst.setString(8, hphone);
pst.setString(9, wphone);
pst.setString(10, mphone);
pst.setString(11, email);
pst.setString(12, occupation);
pst.setString(13, value1);
pst.setString(14, address);
pst.setString(15, value2);


//Add the data into the insurance table
String sql1 = "insert into insurance values (?,?,?,?,?)";
PreparedStatement pst1 = connection.prepareStatement(sql1);
pst1.setString(1,patient_id);
pst1.setString(2, value3);
pst1.setString(3, policynum);
pst1.setString(4, smoker);
pst1.setString(5, referredto);



int numRowsChanged = pst.executeUpdate();
int numRowsChanged1 = pst1.executeUpdate();

// show that the new data has been entered
JOptionPane.showMessageDialog(null,message_update,title,
JOptionPane.INFORMATION_MESSAGE);
res.sendRedirect("index.jsp");

pst.close();
pst1.close();
}
catch(ClassNotFoundException e){
JOptionPane.showMessageDialog(null,error_message + e.getMessage());
}
catch(SQLException e){
//out.println("SQLException caught: " + e.getMessage());
JOptionPane.showMessageDialog(null,error_message + e.getMessage());
res.sendRedirect("index.jsp");
}

catch (Exception e){
out.println(e);
}
finally {
// Always close the database connection.
try {
if (connection != null) connection.close();
}
catch (SQLException ignored){
out.println(ignored);
}
}
}
}
View Answers









Related Pages:
JSP Servlet update patient data - JSP-Servlet
JSP Servlet update patient data  Hi Friend, I'm attaching my inserting patient data servlet as requested. I tried your posted code, its..._update="Data has been successfully inserted!"; String title="Update Message
update
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
Hospital Patient
(); Patient p1=new Patient(); Calendar c=Calendar.getInstance(); Date d... { System.out.println("::::::::Hospital::::::::"); System.out.println("Enter 1.Add a patient 2.Update Patient 3.Search patient 4.Display patients or View status"); ctr
hospital patient
PatientFunction { Scanner s=new Scanner(System.in); public Patient updatePatient(Patient p) { int ctr=0; try { do { System.out.println("::::Update Customer::::\n1.Name 2.Address 3.Age 4.Sex
data update
the data and edit it based on subjectcode(varchar)this should be done using jsp... edit/update data and saved them into that table again...data update  sir, I have a table consist of huge data.I have
data update
the data and edit it based on subjectcode(varchar)this should be done using jsp...data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit
data update
the data and edit it based on subjectcode(varchar)this should be done using jsp...data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit
data update
the data and edit it based on subjectcode(varchar)this should be done using jsp...data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit
data update
the data and edit it based on subjectcode(varchar)this should be done using jsp...data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit
data update
the data and edit it based on subjectcode(varchar)this should be done using jsp...data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit
data update
the data and edit it based on subjectcode(varchar)this should be done using jsp...data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit
data update
the data and edit it based on subjectcode(varchar)this should be done using jsp...data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit
JSP/Servlet to read and update Excel
JSP/Servlet to read and update Excel  Hi Team, My requirement is based upon my input(name) value via one jsp, the program(jsp/servlet) should fetch... access to edit the values and update back to the Excel. So when the user give update
Update / Edit data
, that data will get shown in another page and allow the user to update...Update / Edit data  Hello, i want to create a page to edit or update user data in the data base. the thing is, when i click on submit reference
simple web appllication to insert, update or display from database - JSP-Servlet
in which we can insert, update or delete data from database. i can also display database content on jsp page. please send complete code. thank you mani saurabh...simple web appllication to insert, update or display from database  
update multiple rows in jsp - JSP-Servlet
update multiple rows in jsp  Hi I am trying to do a multiple row update in JSP. code as follows.. > Can you...,author and title in the database. Follow these steps to update these fields: 1
regarding-update the Jsp page itself - JSP-Servlet
regarding-update the Jsp page itself   Joined: Aug 17, 2009 Messages: 12 [Post New]posted Today 10:39:52 PM Quote Edit [Up] I have two Jsp... is i want to update the information on same Jsp page. How can I implement
Read Excel data using JSP and update MySQL databse
Read Excel data using JSP and update MySQL databse  HOw to read excel data using JSP and update MySQl database
Read data from excel file and update database using jsp
Read data from excel file and update database using jsp  read data from excel file and update database using jsp Hi, I am using a MySQL database... format and I need to update MySQL tables with new experimental data. How can I
GPS Patient Tracking System
GPS Patient Tracking System The patients with Alzheimer?s disease or dementia... be filed against them in case of any misfortune with the patient. For solving... the GPS Patient Tracking System at very affordable prices. The GPS Patient
export data to excel sheet - JSP-Servlet
export data to excel sheet  Hi.. how to export data to excel sheet from jsp? and how to update the excel sheet from jsp? and how to get the data from excel sheet? and how to make calculations in excel sheet like total avg
data grid - JSP-Servlet
to implement data grid in jsp Thanks varun kumar  Hi friend, I... information. http://www.roseindia.net/jsp/data-grid.shtml Thanks...data grid  how can we implement data grid (we have data grid
jsp data in excel - JSP-Servlet
jsp data in excel  i have create jsp page which has button for excel.this calls jsp which contains code which has and then code for present data in jsp using table. and getting this data from servlet which has query
Servlet Example To Update Mysql Clob Data
Servlet Example To Update Mysql Clob Data    This example shows how to update CLOB data in the database. In our... to update data of CLOB type in mysql database through the servlet program
data grid - JSP-Servlet
data grid  i am trying to do the example in the following link http://www.roseindia.net/jsp/data-grid.shtml but i am not able to find... this example  Hi friend, To visit again http://www.roseindia.net/jsp/data
update excel sheet using jsp::
update excel sheet using jsp::   Hi Sir,... I have a excel... given excel sheet and display it into another excel sheet using jsp" i am using 'session' to get the empid from one page to another jsp
JSP - JSP-Servlet
thing that by clicking the edit pic we need to access the data display the data in the text boxes of html page then modify the data then when i click the edit then it should be update in the data base  Hi Friend, Try the following
JSP - JSP-Servlet
... In my project I have to insert the data from different JSP pages. I know one...,Update,insert,delete functions to the different JSP pages. From ur JSP page call... details visit to : http://www.roseindia.net/jsp/usingbeansinjsp.shtml Thanks
servlet - JSP-Servlet
to update the data"); } } catch (Exception e..."); PreparedStatement pst = connection.prepareStatement("update emp_info set
JSP - JSP-Servlet
the data in a html form. It must be jsp. Because, html is static where as jsp... Employee ID Enter Employee Name Enter New Name (For UPDATE only) Insert Delete Update Query
textfields and update - SQL
to the textfields using jdbc?and at the same time update the items on the database..   Hello Friend As per ur 1st Q: Read the data from... into jsp page, iterate there and display. In Second Q, u not clarify under which
update jsp
update jsp  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC...;/Controller"> <center> <input type="hidden" name="page" value="update"/>
session concept - JSP-Servlet
session concept  Hello friends, How can we track unexpectedly closing a window when a jsp project running with session concept. And this tracking should update the log in status in data base
multipart/form-data - JSP-Servlet
multipart/form-data  When we are uploading a file we are using the encoded type of form of type multipart/form-data. When we are using... with the example available in http://www.roseindia.net/jsp/file_upload/Sinle
for store data in data base - JSP-Servlet
for store data in data base  i want to a job site, in this site user..... and on 3rd form i use submit button... data of form 1 and 2 can also be store... Friend, We have created 4 jsp files: 1)login.jsp: A:hover
inserting data from radio buttons to database-ERROR - JSP-Servlet
inserting data from radio buttons to database-ERROR  hi, i have already changed the option field of table question. the code which you give me has... it in the code. but still i am getting the error in the update query. please provide
Servlet Response Send Redirect - JSP-Servlet
value to the next jsp? 2. I have a servlet that saves patient data from... the search table.Also post the servlet code that saves the patient data.... what i mean is lets say user does a search on patient data based upon their id
Data fetching from JSP or HTML - JSP-Servlet
Data fetching from JSP or HTML  Hi Deepak, Can u pls help me as i have a problem with jsp/html frameset. my question is how can i fetch the data from frameset which is in html format.pls help me. Thanks
Inserting data on a database in servlet - JSP-Servlet
Inserting data on a database in servlet  Hi I am following the tutorial in this site on servlet and JDBC. I did all the proccedure for connecting to a databse by a servlet.I used the example in "Inserting Data In Database table
read excel data from jsp - JSP-Servlet
read excel data from jsp  Hi how to read excel file from jsp? Excel file is created manually entered data having many sheets? and read the entire sheet and also edit with jsp? pls suggest me?   Hi Friend, 1
Servlet - JSP - JSP-Servlet
",total); when I code this like in my jsp <%ArrayList<Integer> data= new...Servlet - JSP  i used arraylist in servlet as shown ArrayList.... Its showing some exception at line iterator itr; and data= (ArrayList
data are not display in JSP from database - JSP-Servlet
data are not display in JSP from database   i want to finding some data through a SQL query from SQL server database to a JSP page based on some... of this jsp page. like.. School Result and three request parameters 'class', 'from
core java - JSP-Servlet
core java  Thank you very much for your fast reply.. Now it is working... In my project I have to insert the data from different JSP pages. I know... to dbase,Update,insert,delete functions to the different JSP pages. From ur JSP page
Web Related - JSP-Servlet
. How can i update my webpage by inserting the value in database. The webpage should update as soon as possible when value is inserted in database when i... as the JSP pages which will help you in solving your problem. In these JSP pages
jsp/servlet - JSP-Servlet
jsp/servlet  Hello ! How can we call a servlet on a link on html page like a href="servletname"> Call Servlet Is it possible?   Hi friend, I am sending simple application using servlet. This is form
how to store data in XML file - JSP-Servlet
how to store data in XML file  hi i have to store the data for example user id and password in a xml file the input userid and password will be coming from jsp middle ware servlet how to do that?   Hi friend
resultset problem - JSP-Servlet
(rs.next()) { st.executeUpdate("update CSEFIRSTYEARTIMETABLE set p2...'"); } the above update query is executed once not repeatedly error... to repeat the update query upto the wile condition is true? pls send me answer
Sorting data in a jsp using a servlet while implementing comparable - JSP-Servlet
Sorting data in a jsp using a servlet while implementing comparable  ... for displaying them in the jsp: 1. Universal Books Home Page 2. 3. 4... which is stored in the session scope of a servlet. Below is its code
Upload Exce Data into MySql Using Jsp and Servlet - JSP-Servlet
Upload Exce Data into MySql Using Jsp and Servlet  now i am doing a project my concept is to insert the Excel File Data is uploaded and inserted... the following link: http://www.roseindia.net/jsp/upload-insert-csv.shtml Hope
jsp and servlet
submit button,edit button and delete button,through which we can acces the data edit the data and delete the data,using jsp and servlet...jsp and servlet  I want to create a login form,which have many fields

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.