Written some cool source code? Upload it to Programmer's Heaven.

View java\java\bin\manoveg\server\Delete.java

networking authentication program 1.0

Submitted By: manoveg
Rating: (Not rated) (Rate It)


package server;
import java.awt.*;
import java.util.*;
import java.sql.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class Delete
{
 public static void main(String args[])
 {
  SFrontEnd1 frame1=new SFrontEnd1();
  frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame1.show();
 }
}


class SFrontEnd1 extends JFrame implements ActionListener
{
 public static final int WIDTH=300;
 public static final int HEIGHT=300;
 private JTextField Username;
 private JLabel User;
 String acommand3="";
 public SFrontEnd1()
 {
  setTitle("Server");
  setSize(WIDTH,HEIGHT);
  Container contentPane=getContentPane();

  Username= new JTextField("",10);
  Username.setMaximumSize(Username.getPreferredSize());
  Box hbox1=Box.createHorizontalBox();

  User=new JLabel("USERNAME");
  hbox1.add(User);
  hbox1.add(Box.createHorizontalStrut(10));
  hbox1.add(Username);


  Box hbox4=Box.createHorizontalBox();
  JButton Okbutton=new JButton("OK");
  JButton Back1 = new JButton("BACK");
  hbox4.add(Okbutton);
  hbox4.add(Box.createGlue());
  hbox4.add(Back1);
  Okbutton.addActionListener(this);
  Back1.addActionListener(this);

  Box vbox=Box.createVerticalBox();
  vbox.add(hbox1);
  vbox.add(Box.createGlue());
  vbox.add(hbox4);

  contentPane.add(vbox,BorderLayout.CENTER);

  }


 public static Connection dbConnection() throws SQLException , IOException
 {
  Properties props=new Properties();
  FileInputStream in=new FileInputStream("D:/java/java/bin/manoveg/server/database.properties");
  props.load(in);
  in.close();

  String drivers=props.getProperty("jdbc.drivers");
  if(drivers!=null)
  System.setProperty("jdbc.drivers",drivers);
  String url=props.getProperty("jdbc.url");
  String username=props.getProperty("jdbc.username");
  String password=props.getProperty("jdbc.password");
  return DriverManager.getConnection(url,username,password);

  }

  public void actionPerformed(ActionEvent ae)
  {
   acommand3=ae.getActionCommand();
   if(acommand3.equals("OK"))
   {

   SFrontEnd1 SFront = new SFrontEnd1();
   String user=Username.getText();
   String duser="";
   boolean flag=true;

   try
   {

   Connection conn = dbConnection();

   
   String strSQL="DELETE FROM mylogin WHERE username='"+user+"'";
   
   Statement stat=conn.createStatement();
   ResultSet rs = stat.executeQuery("Select username from mylogin");
   while(rs.next())
   {
    duser=rs.getString("username");
    if(duser.equals(user))
     {
      stat.execute(strSQL);
      flag=true;
      break;
     }
    else
    {
     flag=false;
     }
    }
   conn.close();

    if(flag==false)
    {
      throw new SQLException();
     }
   DialogBox11 d = new DialogBox11(SFront,"Successfull","Records successfully Deleted");
   d.setVisible(true);
   Username.setText("");



   }
   catch (SQLException ex)
   {
   DialogBox11 d2 = new DialogBox11(SFront,"Error","The Username Does not exists");
   d2.setVisible(true);
   Username.setText("");
   }
   catch (IOException ex)
   {
   }
 
   }

   else

   if(acommand3.equals("BACK"))
   {
    SFrontEnd31 s6=new SFrontEnd31();
    s6.setVisible(true);
    this.dispose();
    }

 }
}


class DialogBox11 extends Dialog implements ActionListener
{
 String msg="";
 DialogBox11(Frame parent , String title, String msg1)
 {
  super(parent, title , true);
  msg=msg1;
  setLayout(new FlowLayout(FlowLayout.LEFT));
  setSize(300,300);
  Button Ok = new Button("OK");
  add(Ok);
  Ok.addActionListener(this);
 }

 public void actionPerformed(ActionEvent ae1)
 {
  dispose();
 
  }

 public void paint(Graphics g)
 {
  g.drawString(msg,10,170);
  }
}

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.