© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
Quick Links
Easy Studies

Updating the details of user in XMLFile Using Java


This program shows the registration form for the online banking application. In this application any user is assigned with 2 roles and their time constraint is also specified by the administrator of the bank. All these details are stored in an XML file instead of storing in the database. Userís input is concatenated with in the tags. Only with the tag you can access the details of that user. Based on the DTD (Document Type Definition) all the fields are stored in the XML file. XML parser packages are used to get the content of the specified tag name.FileReader and BufferedReader are used for getting the existing values.PrintWriter is used to write the contents into the file.

Updating the details of user in XMLFile Using Java :

/*registration.java*/ <%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%! String get1[]; int f1=0; String get2[]; int f2=0; String p="None"; %> <% f1=0; String fstring=""; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cot=DriverManager.getConnection("jdbc:odbc:banks"); Statement sttt=cot.createStatement(); Statement stmtt=cot.createStatement(); ResultSet resultt=stmtt.executeQuery("select count(*) from duration"); resultt.next(); int totalRecords=resultt.getInt(1); get1=new String[totalRecords]; get2=new String[totalRecords]; System.out.println("Total Records :"+totalRecords); ResultSet rs23t=sttt.executeQuery("select time_from,time_to from duration"); while(rs23t.next()){ get1[f1]=rs23t.getString("time_from"); get2[f1]=rs23t.getString("time_to"); f1++; } } catch(Exception e){ System.out.println(e); } %>

Registration Form

User ID          : 

Password    :  

Sex               :  

Address      :  

Phone No   :  

Role 1      : 

Role 2      : 

Temporal Constraint   :

/*updateXML.java*/ <%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="javax.xml.parsers.DocumentBuilderFactory, javax.xml.parsers.DocumentBuilder,org.w3c.dom.*" %> <% String s=null; String st="",id; int x=0; //if((request.getParameter("id")!=null) && (request.getParameter("T2")!=null) && (request.getParameter("T3")!=null) && (request.getParameter("T4")!=null) && (request.getParameter("T5")!=null) && (request.getParameter("D2")!=null) && (!request.getParameter("D1").equals("None"))){ String ids=(String)session.getAttribute("Id"); System.out.println("sdasd"); String pass=(String)session.getAttribute("Pass"); String sex=(String)session.getAttribute("Sex"); String addr=(String)session.getAttribute("addr"); String phone=(String)session.getAttribute("phone"); String rol1=(String)session.getAttribute("rol1"); String rol2=(String)session.getAttribute("rol2"); String time=(String)session.getAttribute("time"); StringBuffer sts=new StringBuffer(); try{ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse("C:/XML/userbank.xml"); NodeList nl= doc.getElementsByTagName("UserId"); for (int i = 0; i ")){ }else{ st=st+s+"\n"; } System.out.println(sts.toString()); } }catch(Exception e){ System.out.println("Exception"+e); } String idinsert=""+ids+""+"\n"; String passinsert=""+pass+""+"\n"; String sexinsert=""+sex+""+"\n"; String addrinsert="
"+"\n"; String phinsert=""+phone+""+"\n"; String roleinsert1=""+rol1+""+"\n"; String roleinsert2=""+rol2+""+"\n"; String timeinsert=""+"\n"; sts.append(st); sts.append(idinsert); sts.append(passinsert); sts.append(sexinsert); sts.append(addrinsert); sts.append(phinsert); sts.append(roleinsert1); sts.append(roleinsert2); sts.append(timeinsert); sts.append(""); try{ PrintWriter out1 = new PrintWriter(new FileWriter("C:/XML/userbank.xml")); out1.print(sts.toString()); out1.close(); response.sendRedirect("fine.jsp"); } catch(Exception r){ response.sendRedirect("unsuc.jsp"); } } //} %>

Sample ScreenShot:

SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑