JSP Servlet update patient data

Ads

 
 

Share on Google+Share on Google+

john
JSP Servlet update patient data
0 Answer(s)      7 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);
}
}
}
}
Ads
View Answers
Ads









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
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
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
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
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
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 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
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  
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
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
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
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
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
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
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
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
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
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"/>

Ads

 
Advertisement null

Ads