The following are two Java Servlet Server side programs and one HTML Client Side. HTML Program will send client side information for find out a specific or selected data from M.S.Access/SQL table and Java Servlet (Server Side) program will display specific records from database. and second java servlet program will update records into M.S.Access Table. For this first of all you need to create a M.S.Access database or SQL... but in this example I'm using M.S.Access. Create one table in M.S Access as shown below:
Table Name : [ICTCashBook.mdb]-Download
Primary Key : VoucherNo
Foreign Key : Nil
Column Definition:
Column Name Data Type
ID AutoNumber
Session Text
Month Text
DD Number
MM Number
YY Number
VoucherNo Number
Articles Memo
FromWhichPurchsed Memo
Amount Number
Remarks Memo
Table Description:
Column Name Description
ID Create AutoNumber for image id
Session insert Session for ex. 2011-12
Month insert month in text...
DD insert date in numeric
MM insert month in numeric
YY insert year in numeric
VoucherNo insert unique numeric no
Articles insert text
FromWhichPurchsed insert text
Amount insert numeric value
Remarks insert text/numeric value
After create table in M.S. Access database now you will create
DSN.
Following is the Java Servlet source code of the UpdateIncomeExpenditure.java
/*
===========================================================
File Name : UpdateIncomeExpenditure.java
WebSite : http://javaproglang.blogspot.in/
Facebook : https://www.facebook.com/AdvanceJavaProgramming
Twitter ID : https://twitter.com/AdvanceJava
Created By : Bintu Chaudhary
===========================================================
*/
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Calendar;
public class UpdateIncomeExpenditure extends HttpServlet
{
Connection conn;
Statement stmt;
ResultSet rs;
PrintWriter pw;
String sql,sql_insert;
int int_pre_amt,int_total;
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");
pw=res.getWriter();
String url="jdbc:odbc:khokhar";
String month =req.getParameter("month");
String year =req.getParameter("year");
String str_mm="Month";
String str_yy="Year";
pw.println("");
String STRSESS,STRDD,STRMM,STRYY,STRCS,STRAMT,STRTOT,STRREMARKS;
pw.println("Update Income/Grants ");
pw.println(" ");
pw.println(" ");
pw.println("");
pw.println("");
pw.println("");
pw.println(" ");
pw.println("
");
if(month.equalsIgnoreCase(str_mm) || year.equalsIgnoreCase(str_yy))
{
pw.println("Please Select Month and Year !!!");
pw.println(" ");
}
else
{
try
{
int int_yy=Integer.parseInt(year);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
url="jdbc:odbc:khokhar";
conn=DriverManager.getConnection(url);
stmt=conn.createStatement();
pw.println("");
String sql="Select * from ComputerCashBookExpenditure Where Month='"+month+"' and YY="+year;
rs=stmt.executeQuery(sql);
if(rs.next()==false)
{
pw.println(" ");
pw.println("Sorry!!! There is No Entry about - "+month+" - "+int_yy+" ");
pw.println(" ");
pw.println("");
}
else
{
pw.println("");
pw.println("Income - "+month+" - "+int_yy+" Fund Account ");
pw.println("
");
pw.println("");
pw.println(" ");
pw.println(" ");
pw.println(" ");
stmt.close();
conn.close();
}
pw.println(" ");
}
catch(Exception e)
{
pw.println(e.getMessage());
}
}
}
}
Now, second java servlet program...
/*
===========================================================
File Name : UpdateIncomeExpenditures.java
WebSite : http://javaproglang.blogspot.in/
Facebook : https://www.facebook.com/AdvanceJavaProgramming
Twitter ID : https://twitter.com/AdvanceJava
Created By : Bintu Chaudhary
===========================================================
*/
import java.sql.*;
import javax.naming.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class UpdateIncomeExpenditures extends HttpServlet
{
boolean stat;
Connection conn;
Statement stmt;
ResultSet rs;
PrintWriter pw;
PreparedStatement pre_sess,pre_res;
String url;
String sql_chk;
String sql_six;
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");
pw=res.getWriter();
try
{
String ses = req.getParameter("sess");
String mnth = req.getParameter("month");
String sess[] = req.getParameterValues("sess");
String month[] = req.getParameterValues("month");
String vno[] = req.getParameterValues("vno");
String dd[] = req.getParameterValues("dd");
String mm[] = req.getParameterValues("mm");
String yy[] = req.getParameterValues("yy");
String articles[]= req.getParameterValues("articles");
String pur[] = req.getParameterValues("pur");
String amount[] = req.getParameterValues("amount");
String remarks[] = req.getParameterValues("remarks");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
url="jdbc:odbc:khokhar";
conn=DriverManager.getConnection(url);
stmt=conn.createStatement();
for(int i=0;iUpdate Income Grants ");
pw.println("");
pw.println("");
pw.println(" ");
pw.println("
");
pw.println("");
stmt.close();
conn.close();
pw.println(" ");
pw.println("");
pw.println("");
pw.println("");
}
catch(SQLException se)
{
System.out.println(se.getMessage());
pw.println("Update Expenditure ");
pw.println("");
pw.println("Currently There is a Problem with the Database");
pw.println(" Please Try Again ");
pw.println("");
pw.println("");
}
catch(ClassNotFoundException cnfc)
{
System.out.println(cnfc.getMessage());
}
}
}
"Start -> All Programs -> Apache Tomcat 4.0 -> Start Tomcat." and minimize window
How to Install Apache Tomcat 4.0 then Click Here
and for Download Apache Tomcat 4.0 then Click Here
Now compile the above both code using javac compiler...
C:\jdk1.4\bin>javac UpdateIncomeExpenditure.java -classpath "C:/Program Files/Apache Tomcat 4.0/common/lib/servlet.jar"
C:\jdk1.4\bin>javac UpdateIncomeExpenditures.java -classpath "C:/Program Files/Apache Tomcat 4.0/common/lib/servlet.jar"
Now, copy "UpdateIncomeExpenditure.class" and "UpdateIncomeExpenditures.class" Files from c:/jdk1.4/bin/ and then paste it under below dir...
"C:/Program Files/Apache Tomcat 4.0/webapps/examples/WEB-INF/classes/"
or use below command
C:\jdk1.4\bin>copy UpdateIncomeExpenditure.class "C:/Program Files/Apache Tomcat 4.0/webapps/examples/WEB-INF/classes/"
C:\jdk1.4\bin>copy UpdateIncomeExpenditures.class "C:/Program Files/Apache Tomcat 4.0/webapps/examples/WEB-INF/classes/"
or you can use "*.class" for copy all classes...
C:\jdk1.4\bin>copy *.class "C:/Program Files/Apache Tomcat 4.0/webapps/examples/WEB-INF/classes/"
Now Open any web browser and type client side URL into address bar as below...
http://localhost:8080/EditIncomeExp.html
HTML Form for retrieve selecting information
Open Records for Updating
Final Update Reocrd using Java Servlet Programming
Nice Article.
ReplyDeleteAWS Training in Hyderabad
Best AWS Training in Hyderabad
AWS Online Training
AWS Training Online
AWS Training In Bangalore
Our training will be focused on aiding placements too. We have separate HR team professionals who will take care of all your interview needs. Our Core Java Training in Gurgaon Course Fees is very moderate compared to others. We are the main Core Java training institute who can share video reviews of every one of our students.
ReplyDeleteFor More Info: Core Java Training in Gurgaon
Your blog is in a convincing manner, thanks for sharing such an information with lots of your effort and time
ReplyDeletesql server dba online training
sql dba course
sql dba training
Wow what a great blog, i really enjoyed reading this, good luck in your work. Sap Mm Training Institute In Bangalore | Dot Net Training Institute In Bangalore | Selenium Training Institute in Bangalore
ReplyDeleteThankyou for sharing such as nice post. It is really helpful for developer, Keep it sharing
ReplyDeleteVisit our website accessdatabasedevelopment.co.uk/ for develop custom databases tailored to your business needs and providing your business with a competitive advantage by enabling you to increase efficiency, enhance quality of service and make the work lives of staff simpler. We microsoft access database development London specialise in building bespoke business database solutions and form creation in ms access using industry standard tools such as Microsoft Access.
microsoft access developer London