JSP Servlet update patient data

JSP Servlet update patient data

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 Tutorials/Questions & Answers:
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
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
Advertisements
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
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
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
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
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
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
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  
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
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
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
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
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
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
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 example, servlet InsertClobExample takes url for the CLOB data (the url
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
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
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
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
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 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
retrieving of data from one jsp to another jsp - JSP-Servlet
retrieving of data from one jsp to another jsp  using jsp i m displaying a table ,in table i m displaying a radio button then values like id,name etc... that is used for different jsp please help me sir... thanks in advance   Hi
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
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"/>
how to store data in other table using servlet and jsp
how to store data in other table using servlet and jsp  pls can anyone tell how to store data in other table using servlet and jsp and want to display that data too.and the data in first table must be same.pls help
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
JSP - Update displayed content & session variables when user clicks on a button - JSP-Servlet
JSP - Update displayed content & session variables when user clicks on a button  Hi, I'm trying to setup a form in which the user can click... JSP to do some internal check and then increment the value of a number
adding DSN in Data Sources - JSP-Servlet
adding DSN in Data Sources  I have added DSN the way you have told and it has been added in the data sources as online_exam is shown in the ODBC... org.apache.jasper.JasperException: An exception occurred processing JSP page
callable statement,stored procedure for insert data and also for update data into oracle database using jsp
callable statement,stored procedure for insert data and also for update data... procedure for inserting data into oracle database as bind variable and same for update also thank you
JSP - Update displayed content & session variables when user clicks on a button - JSP-Servlet
JSP - Update displayed content & session variables when user clicks... JSP to do some internal check and then increment the value of a number... combination of JSP and javascript would work since my knowledge base is in Java. Here
servlet code to update password?
servlet code to update password?  Create a servlet page which helps the user to update his password. The user should give the username,old password,new password,confirm password. The updation is applicable only for valid
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  I am using a single jsp form.. i did not get from another form.. i do not use 2 jsp form.. all.... Note: I am using only this jsp form.. i do not use
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
how to retrieve blob data - JSP-Servlet
how to retrieve blob data  How to retrieve the BLOB table having single row single column in Database containing memory information using JSP...://www.roseindia.net/jsp/retrieve-image.shtml Thanks
excel sheet reading and using that data - JSP-Servlet
excel sheet reading and using that data  i have to do a read a excel sheet file of a employee record and then i have to use a employee details to send mail to those employees how to do in jsp sir please help me sir.. Thanks
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  For example, In Employee.jsp form, When i click employee id value in combo box ,the related employee name will be displayed in text field
Data Capture from resume - JSP-Servlet
Data Capture from resume  Hi Sir, In My Application, when i Upload a resume the relevant columns like name,phone,email,skills etc need to be captured automatically and must be stored into the database. Please solve
How to retrieve data using combo box value in jsp? - JSP-Servlet
How to retrieve data using combo box value in jsp?  Hi freind, I already post this question. I need urgent help from u. pl response me... the following link: http://www.roseindia.net/jsp/comboSelect.shtml Hope

Ads