Académique Documents
Professionnel Documents
Culture Documents
Digital Assignment - 2
USING THEN COMPARING, FLAT FILE PROCESSING AND
DBMS APPROACH TO ACCESS AND MANIPULATE DATA
GAURI TYAGI
15BCE0126
COURSE INSTRUCTOR
Dr. Anthoniraj A
Honor Code
I certify that I have properly cited any material taken from other sources and have obtained
permission for any copyrighted material included in this report. I take full responsibility for any code
submitted as part of this assignment and the contents of this report.
Page 2 of 22
Abstract
This assignment is an attempt to compare the DBMS approach head-to-head with Flat-File
Processing by using them to access and manipulate a data set. The goal was to understand the
workings of data retrieval and manipulation by the two methods.
1. Introduction
Resource Software Specifications
o Data Set
Data Set Title: Women and currently married women by present age, number of
births last year by sex and birth order - Tamil Nadu
Link: http://tinyurl.com/da2-dataset
Released under: National Data Sharing and Accessibility Policy (NDSAP)
Contributor: Ministry of Home Affairs, Registrar General and Census
Commissioner
Published on: September 07,2015
o Programming Language
o DBMS Software
Page 3 of 22
User can
access choose
records in the
input range
Accesses
complete data
set by reading
open file
Clears the
input/output
data fields
Accesses
complete data
set through
arrays.
SOURCE CODE
Page 4 of 22
import java.io.*;
import java.util.*;
import javax.swing.JOptionPane;
//imports
Page 5 of 22
jTextArea1.append(str);
//reads lines until no line==null
jTextArea1.append("\n");
}
System.out.println(str);
}
catch (IOException e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
Page 6 of 22
Try
{
BufferedReader br = new BufferedReader(new FileReader(new File("F:\\Study\\SEM
3\\DBMS\\DA2\\a.csv")));
String line = "";
int rows=0;
String data[][] = new String[1000][13];
while ((line = br.readLine()) != null)
{
String value[] = line.split(",", 13); //the line must be splited and stored in a 1D array
for (int j=0; j<13; j++)
data[rows][j] = value[j];
//transfer of our array of splited elements one by
one to our 2D array
rows++;
}
for(int i=0;i<rows;i++)
{
for(int j=0;j<13;j++)
{
jTextArea1.append(data[i][j]+'\t');
}
jTextArea1.append("\n");
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
Page 7 of 22
//from record m
//to record n
Page 8 of 22
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
Page 9 of 22
Page 10 of 22
Page 11 of 22
4. DBMS Manipulation
<<Processing your DBMS with same Programming Language, Add necessary source code,
SQL Queries and output/screenshots>>
NOTE: All SQL queries have been marked in red
Table
Component
Page 12 of 22
Source Code
//imports
import javax.swing.table.DefaultTableModel;
import java.sql.*;
import javax.swing.JOptionPane;
Statement stmt=con.createStatement();
String q1="Select * from da2;";
ResultSet rs=stmt.executeQuery(q1);
while(rs.next())
{
String a=rs.getString(1);
String b=rs.getString(2);
String c=rs.getString(3);
String d=rs.getString(4);
String e=rs.getString(5);
String f=rs.getString(6);
String g=rs.getString(7);
String h=rs.getString(8);
String i=rs.getString(9);
String j=rs.getString(10);
String k=rs.getString(11);
String l=rs.getString(12);
String m=rs.getString(13);
t1.addRow(new Object[]{a,b,c,d,e,f,g,h,i,j,k,l,m});
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{}
}
Page 14 of 22
Source Code
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
Class.forName("java.sql.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
Statement stmt=con.createStatement();
String a_Name=jTextField1.getText();
String a_Type=jTextField2.getText();
String age_Group=jTextField3.getText();
String t_Women=jTextField4.getText();
String t_CMWomen=jTextField5.getText();
String ly_Male=jTextField6.getText();
String ly_Female=jTextField7.getText();
String ly_O1=jTextField8.getText();
String ly_O2=jTextField9.getText();
Page 15 of 22
String ly_O3=jTextField10.getText();
String ly_O4=jTextField11.getText();
String district_Code=jTextField12.getText();
String state_Code="33";
Page 16 of 22
GUI Design
Source code
//code for populate list button
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
DefaultListModel m1=(DefaultListModel)jList1.getModel();
DefaultListModel m2=(DefaultListModel)jList2.getModel();
DefaultListModel m3=(DefaultListModel)jList3.getModel();
Page 17 of 22
try {
Class.forName("java.sql.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
Statement stmt=con.createStatement();
try {
Class.forName("java.sql.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(query);
while (rs.next()) {
jTextField1.setText(rs.getString("Total_Women"));
jTextField2.setText(rs.getString("Currently_Married_Women"));
jTextField3.setText(rs.getString("Births_LY_Male"));
jTextField4.setText(rs.getString("Births_LY_Female"));
jTextField5.setText(rs.getString("Births_LY_Order_1"));
jTextField6.setText(rs.getString("Biths_LY_Order_2"));
Page 19 of 22
jTextField7.setText(rs.getString("Births_LY_Order_3"));
jTextField8.setText(rs.getString("Births_LY_Order_4"));
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField7.setText("");
jTextField8.setText("");
m1.removeAllElements();
m2.removeAllElements();
m3.removeAllElements();
Page 20 of 22
Output
Page 21 of 22
5. Conclusion
Flat File Processing is cumbersome. Records in the CSV file had to be split, and
each token had to be transferred to a 2D string array.
Type conversion to be able to work with data is another problem
Although not implemented in this assignment, deletion will be a tedious process as
the huge data records will have to be shifted up and down the array to maintain
consistency.
There is no mapping between any two files. i.e.; any two dependent files are not
linked.
Data Dependence: . If the format of any of the file is changed, then the program for
processing this file needs to be changed. That is smallest change in the file affect all
the programs and need changes in all them.
6. References
>NA
---------------------x----------------------
Page 22 of 22