Database manager Application using java
This application is used to manage the database. It means create new database , delete the database, sort the database etc. This application is programmed in java for GUI (graphical user interface) purpose I use swings concept. In this project we learn the how to manage the data and how it retrieves the data from the file. And we also focus on visuals to make attractive application for suppose designing or moving frames or visual etc. we learn these in we learn these in this project in below program expalined neatly. Follow thatCode for Each Frame and how its work clearly explained in below:
login page
Code:
//when we press the login button this code will excuted
private void logMouseClicked(java.awt.event.MouseEvent evt) {
login();
Toolkit.getDefaultToolkit().beep();
// TODO add your handling code here:
}
public void login()
{
Form obj= new Form();
String id= t1.getText();
String ps= t2.getText();
FileReader fr1= new FileReader(“Data.txt”);
BufferedReader br1= new BufferedReader(fr1);
try {
while((s=br1.readLine())!=null)
{
count++;
StringTokenizer str = new StringTokenizer(s);
while(str.hasMoreTokens())
{
//Readig Tokens one by one
String s1= str.nextToken();
String s2= str.nextToken();
String s3= str.nextToken();
String s4= str.nextToken();
String s5= str.nextToken();
String s6= str.nextToken();
String s7= str.nextToken();
String s8= str.nextToken();
if(s1.equals(id) && ps.equals(s8))
{
n=1;
obj.id.setText(“Welcome “+s2);
obj.setVisible(true);
this.setVisible(false);
obj.setLocationRelativeTo(null);
}
}
}
} catch (Exception ex) {
}
// user enter wrong password and ID. It shows the wrong password or Id not register will display the frame
if(n!=1 &&p!=2)
{
this.setVisible(false);
wrongpass wrong= new wrongpass();
wrong.setVisible(true);
wrong.setLocationRelativeTo(null);
}
}
Registration for new user
- when we in login page we press the register icon it excutes this code.
- n1, n1, n3, n4, n5, n6, n7, p1,p2 varaibles for textfields.
- sp1, sp2, sp3 are spinners (date of birth).
- gen is variable for gender selection list.
- Code: {
String f1= n1.getText();
String f2= n2.getText();
String id= n3.getText();
//String dob= n4.getText();
public void check()
Object sp=sp1.getValue();
int i =Integer.parseInt(sp.toString() ); //For get the spinner values
Object mon=sp2.getValue();
int i1 =Integer.parseInt(mon.toString() );
Object year=sp3.getValue();
int i2 =Integer.parseInt(year.toString() );
String d=i+”/”+i1+”/”+i2;
String mail= n5.getText();
String ph= n6.getText();
//c ph1= Integer.parseInt(ph);
String add= n7.getText();
String pass= p1.getText();
String pass1= p2.getText();
String f3= f1+f2;
// table.getModel().setValueAt(f3, 2, 0);
String gender=” “;
int n= gen.getSelectedIndex();
if(n==1)
{
gender =”Male”;
}
else if(n==2)
{
gender=”Female”;
}
else
{
}
// these are for background colors, fore ground colors , button background colors and joptionpane color selection codes in html format.
UIManager UI = new UIManager();
UIManager.put(“OptionPane.background”, Color.gray);
UIManager.put(“Button.background”, Color.pink);
UIManager.put(“Panel.background”, Color.gray);
UIManager.put(“OptionPane.foreground”, Color.white);
UIManager.put(“OptionPane.messagebackground”, Color.gray);
// write data into database list or textfile
try{
FileWriter fw;
fw = new FileWriter(“Data.txt”,true);
BufferedWriter bw;
bw = new BufferedWriter(fw);
if(id.isEmpty()|| f1.isEmpty() ||f2.isEmpty() || mail.isEmpty() || ph.isEmpty() || add.isEmpty()) {
JOptionPane.showMessageDialog(null, new JLabel(“<html><h3><font color=’white’>Fillup All Columns!!!</font></h3></html>”), “INFORMATION”, JOptionPane.INFORMATION_MESSAGE);
}
else if(!pass.equals(pass1))
{
JOptionPane.showMessageDialog(null, new JLabel(“<html><h3><font color=’white’>Enter Correct Password to Save !!!</font></h3></html>”), “INFORMATION”, JOptionPane.INFORMATION_MESSAGE);
}
else if(n==0)
{
glabel.setText(“Choose one”);
JOptionPane.showMessageDialog(this,”Please Select gender!!!!”);
}
else {
bw.write(id+” “+f3+” “+d+” “+gender+” “+mail+” “+ph+” “+add+” “+pass1+”\n”);
JOptionPane.showMessageDialog(null, new JLabel(“<html><h3><font color=’white’> Details Successfully Stored!! </font></h3></html>”), “INFORMATION”, JOptionPane.INFORMATION_MESSAGE);
this.setVisible(false);
Login ob= new Login();
ob.setVisible(true);
ob.setLocationRelativeTo(null);
}
bw.close();
fw.close();
}
catch(IOException e)
{}
}
//when we click on the tick it goes to the login page to login
private void homeMouseClicked(java.awt.event.MouseEvent evt) {
this.setVisible(false);
Login obj= new Login();
obj.setVisible(true);
obj.setLocationRelativeTo(null);
}
//for reset the all textfields or clear the textfileds when we press the reset button
private void reloadMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
n1.setText(null);
n2.setText(null);
n3.setText(null);
// n4.setText(null);
n5.setText(null);
n6.setText(null);
n7.setText(null);
n8.setText(null);
p1.setText(null);
p2.setText(null);
}
}
Home page for application all options is there
When we enter the correct userId and password it comes to this page .. in this page few option is there .Delete, search and total database list.
Code:
// when we press the Delete button this action will done
private void save2ActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false);
Delete obj;
try {
obj = new Delete();
obj.setVisible(true);
obj.setLocationRelativeTo(null);
} catch (IOException ex) {
Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex);
}
}
// when we press the Search button this action will done
private void searchActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.setVisible(false);
Search search= new Search();
search.setVisible(true);
search.setLocationRelativeTo(null);
}
// when we press the Logout button this action will done
private void logActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false);
Login obj= new Login();
obj.setVisible(true);
obj.setLocationRelativeTo(null);
}
// when we press the information button this action will done
private void rMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
this.setVisible(false);
about obj= new about();
obj.setVisible(true);
obj.setLocationRelativeTo(null);
}
}
Database list it retrive the data from the file - when we press the Database button in above page it comes this frame.
- It displays the all data in your database.
- And it have some options like search , count of total databases, refresh the updata database, delete the databaseand back to home page.
Code:
// when we press the Delete icon delete window will display
private void save2ActionPerformed(java.awt.event.ActionEvent evt) {
public void check()
{
FileReader fr1= new FileReader(“Data.txt”);
BufferedReader br1= new BufferedReader(fr1);
try {
while((s=br1.readLine())!=null)
{
StringTokenizer str = new StringTokenizer(s);
while(str.hasMoreTokens())
{
int k=0;
String s1= str.nextToken();
String s2= str.nextToken();
String s3= str.nextToken();
String s4= str.nextToken();
String s5= str.nextToken();
String s6= str.nextToken();
String s7= str.nextToken();
String s8= str.nextToken();
// insert the data from file to table
table.getModel().setValueAt(s2,p , k);
table.getModel().setValueAt(s1,p , ++k);
table.getModel().setValueAt(s4,p, ++k);
table.getModel().setValueAt(s3,p, ++k);
table.getModel().setValueAt(s5,p , ++k);
table.getModel().setValueAt(s6,p, ++k);
table.getModel().setValueAt(s7,p , ++k);
}
p++;
}
} catch (Exception ex || FileNotFoundException ex) {
}
}
// when we press the home icon .. home page will appears and this page will disapper
private void homeMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
this.setVisible(false);
Form obj= new Form();
obj.setVisible(true);
obj.setLocationRelativeTo(null);
}
// when we press the search icon .. search page will appear and this page will disappear
private void searMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
this.setVisible(false);
Search obj=new Search();
obj.setVisible(true);
obj.setLocationRelativeTo(null);
}
// when we press the count icon .. count the all users in your database
private void couMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
BufferedReader ibr=new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(“Data.txt”)));
this.setVisible(false);
Countframe obj= new Countframe();
int count=0;
String s=” “;
try {
FileReader fr= new FileReader(“Data.txt”);
BufferedReader br=new BufferedReader(fr);
try {
while((s=br.readLine())!=null)
{
count=count+1;
}
} catch (IOException ex) {
Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex);
}
}
catch (FileNotFoundException ex) {
Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex);
}
try {
while((s=ibr.readLine())!=null)
{
count=count+1;
}
} catch (IOException ex) {
Logger.getLogger(List.class.getName()).log(Level.SEVERE, null, ex);
}
obj.label.setText(“Total Database in list Count is: “+count);
obj.setVisible(true);
obj.setLocationRelativeTo(null);
// JOptionPane.showMessageDialog(this,”);
}
// when we press the refresh icon .. updated list will display
private void reMouseClicked(java.awt.event.MouseEvent evt) {
check();
}
// when we press the delete icon .. delete page will appears and this page will disapper
private void delMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
this.setVisible(false);
try{
Delete del = new Delete();
del.setVisible(true);
del.setLocationRelativeTo(null);
}
catch(Exception e)
{}
}
- when we press the Search button in above page it comes to this frame.
- Enter the id number it checks the database .then it exists it display the datails of user. Otherwise popup will display.
Code:
// when we press the home icon .. home page will appears and this page will disapper
private void homeMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
Form obj= new Form();
obj.setVisible(true);
obj.setLocationRelativeTo(null);
this.setVisible(false);
}
// when we enter id and press the search icon this code will excutes whether entered is existed or not
public void check()
{
String s1=” “;
int k=0;
s1 = sr1.getText();
try{
FileReader fr;
fr = new FileReader(“Data.txt”);
BufferedReader br = new BufferedReader(fr);
String s=” “;
while((s=br.readLine())!=null){
StringTokenizer st = new StringTokenizer(s);
while(st.hasMoreTokens())
{
String str= st.nextToken();
if(!str.equals(s1)){
break;
}
else if(str.equals(s1)) {
k=2;
String name= st.nextToken();
String dob= st.nextToken();
String gen= st.nextToken();
String mail= st.nextToken();
String ph= st.nextToken();
String add= st.nextToken();
//JOptionPane.showMessageDialog(this,”Name: “+name+”\n”+”DOB :”+dob+”\n”+”Gender :”+gen+”\n”+”Mail :”+mail+”\n”+”Ph-No :”+ph+”\n”+”City :”+add);
nam.setText(“Name: “+name);
i.setText(“ID: “+s1);
g.setText(“Gender: “+gen);
d.setText(“DOB: “+dob);
m.setText(“Mail: “+mail);
p1.setText(“Ph-no: “+ph);
c.setText(“City: “+add);
break;
}
}
}
}
catch(Exception e)
{}
//JOptionPane.showMessageDialog(this, k+” “+n);
if(n!=1 && k!=2)
{
UIManager UI = new UIManager();
UIManager.put(“OptionPane.background”, Color.gray);
UIManager.put(“Button.background”, Color.pink);
UIManager.put(“Panel.background”, Color.gray);
UIManager.put(“OptionPane.foreground”, Color.white);
UIManager.put(“OptionPane.messagebackground”, Color.gray);
// JOptionPane.showMessageDialog(null, new JLabel(“<html><h3><font color=’white’>Not Exist!!! Enter Correct ID!!!!</font></h3></html>”), “INFORMATION”, JOptionPane.INFORMATION_MESSAGE);
this.setVisible(false);
searchwrong obj= new searchwrong();
obj.setVisible(true);
obj.setLocationRelativeTo(null);
}
}
private void picMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
check();
}
// when we press the refresh icon .. textfileds will refresh and clear
private void reloadMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
sr1.setText(null);
nam.setText(“Name :”);
i.setText(“ID :”);
g.setText(“Gender :”);
d.setText(“DOB :”);
m.setText(“Mail :”);
p1.setText(“Ph-no :”);
c.setText(“City :”);
}
// when we press the back arrow icon .. it goes the database list form
private void backMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
this.setVisible(false);
List obj1= new List();
obj1.check();
obj1.setLocationRelativeTo(null);
obj1.setVisible(true);
}
}
Delete the selected ID database for ur list
- Here i used the list to select the particular id to delete .
- it is easy delete for user.
Code:******************Give your comments on this post*************
public int i;
public String str=””;
// when we select the particular Database .
private void listValueChanged(javax.swing.event.ListSelectionEvent evt) {
// TODO add your handling code here:
deletelogic obj= new deletelogic();
i=list.getSelectedIndex();
try {
str= obj.check(i);
text.setText(str);
}
catch(Exception e)
{}
}
// when we press the delete icon .. this action will excuted
private void butMouseClicked(java.awt.event.MouseEvent evt) {
deletelogic obj= new deletelogic();
try{
obj.delete(i);
set();
str= obj.check(i);
text.setText(str);
}
catch(Exception e){}
//String s= obj.stot;
// JOptionPane.showMessageDialog(this, s);
}
// Delete logic to remove the user data from database and text file
public void set() throws FileNotFoundException, IOException
{
int count=0,i=-1;
FileReader fr= new FileReader(“Data.txt”);
BufferedReader br = new BufferedReader(fr);
String s=” “;
while(br.readLine()!=null)
{
count++;
}
String[] arr= new String[count];
fr= new FileReader(“Data.txt”);
br = new BufferedReader(fr);
while((s=br.readLine())!=null)
{
StringTokenizer st = new StringTokenizer(s);
while(st.hasMoreTokens())
{
i++;
String str= st.nextToken();
arr[i]=str;
break;
}
}
//String s1= arr[3];
// JOptionPane.showMessageDialog(null,s1);
list.setListData(arr);
}
public void check() throws FileNotFoundException, IOException
{
int n=0;
FileReader ff= new FileReader(“Data.txt”);
BufferedReader bb= new BufferedReader(ff);
String id= text.getText();
String s1=””,st2=””;
while((s1=bb.readLine())!=null)
{
StringTokenizer str= new StringTokenizer(s1);
while(str.hasMoreTokens())
{
String st= str.nextToken();
String st1= str.nextToken();
String st22= str.nextToken();
String st3= str.nextToken();
String st4= str.nextToken();
String st5= str.nextToken();
String st6= str.nextToken();
String st7= str.nextToken();
if(st.equals(id))
{
n=1;
}
else
st2+=s1+”\n”;
}
}
bb.close();
ff.close();
FileWriter fr= new FileWriter(“Data.txt”);
BufferedWriter br= new BufferedWriter(fr);
br.write(st2);
br.close();
fr.close();
if(n==1)
{
this.setVisible(false);
deletesuccess obj=new deletesuccess();
obj.setVisible(true);
obj.setLocationRelativeTo(null);
}
else
{
this.setVisible(false);
deletewrong obj= new deletewrong();
obj.setVisible(true);
obj.setLocationRelativeTo(null);
//JOptionPane.showMessageDialog(this,”ID not Registered!!!”);
}
}




