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-ServletJSP 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 ExcelJSP/
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-Servletupdate 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-Servletregarding-
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-Servletjsp 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
data grid - JSP-Servletdata 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 jspRead
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 fetching from JSP or HTML - JSP-ServletData 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-Servletmultipart/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-Servletread 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-ServletInserting
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-Servletdata 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
for store data in data base - JSP-Servletfor 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-Servlethow 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
export data to excel sheet - JSP-Servletexport
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
update jspupdate 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"/>
adding DSN in Data Sources - JSP-Servletadding 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
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
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-Servlethow 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-Servletexcel 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
Data Capture from resume - JSP-ServletData 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