Changing database entry only by entering a password

I'm trying to have a page that displays a persons data and each person is assigned to an agent. I want the field where the persons agent can be changed to have a password.
i.e if some other agent tries to change the persons agent they have to fill in the original agents password, so that only the agent assigned can change the assigned agent to a new one.
I hope that makes some sense some example code would be great.
Thanks Paul :)

THANK YOU SO MUCH!
It is a client-side setup. I'm afraid though i have a few more questions. I read your post a few times to gleam all i could.
I understand most of it, I'm just unsure of how to "connect to database to get the password corresponding to this user name". You said to use an int if i wanted different access levels the problem is that i need different access levels and each 'agent'/'user name' to only be able to edit the properties they have added to the database. how could i achieve this?
this is what i've come up with, it work but when i press login i get two errors:
* There is an error with your username, please fill it in exactly as assigned.
* You are not logged in, or your username does not exist or your password is not correct.
import javax.swing.event.*;
import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.util.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; // used for ActionListener
public class Login extends JFrame implements ActionListener
    private JComboBox cmbNames;
    private JLabel lblUsrName = new JLabel ("User name");
    private JLabel lblPass = new JLabel ("Password");
    private JTextField txtUsrName = new JTextField ();
    private JTextField txtPass = new JTextField ();
    private JPasswordField pasPass = new JPasswordField ();
    private JButton btnLogin = new JButton ("Login");
    private JButton btnCancel = new JButton ("Cancel");
    private boolean loggedIn = false; //or you can have an int here to show access level with 0=notlogged, 1=user, 2=admin for example
    private Connection conn = null;
    private Container c;
    public Login ()
        super ("Agent Login Panel");
        setDefaultCloseOperation (EXIT_ON_CLOSE);
        setSize (235, 160);
        setResizable (false);
        show ();
        Dimension dim = Toolkit.getDefaultToolkit ().getScreenSize ();
        int w = getSize ().width;
        int h = getSize ().height;
        int x = (dim.width - w) / 2;
        int y = (dim.height - h) / 2;
        setLocation (x, y);
        c = getContentPane ();
        c.setLayout (null);
        connectToDB ();
        populateFrame ();
        show ();
    public void connectToDB ()
        try
            Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
        catch (ClassNotFoundException c)
            JOptionPane.showMessageDialog (this, "Error loading driver", "Error", JOptionPane.ERROR_MESSAGE);
        try
            conn = DriverManager.getConnection ("jdbc:odbc:BASE");
        catch (Exception e)
            JOptionPane.showMessageDialog (this, "Error with connect", "Error", JOptionPane.ERROR_MESSAGE);
    public void dispose ()
        super.dispose ();
        try
            conn.close ();
        catch (SQLException e)
            JOptionPane.showMessageDialog (this, "Error with Disconnect", "Error", JOptionPane.ERROR_MESSAGE);
    public void populateFrame ()
        c.add (lblUsrName); // horz vert
        lblUsrName.setBounds (30, 20, 75, 30);
        c.add (lblPass); //       width height
        lblPass.setBounds (30, 50, 75, 30);
        c.add (txtUsrName);
        txtUsrName.setBounds (105, 20, 100, 30);
        c.add (pasPass);
        pasPass.setBounds (105, 50, 100, 30);
        c.add (btnLogin);
        btnLogin.addActionListener (this);
        btnLogin.setBounds (20, 85, 95, 30);
        c.add (btnCancel);
        btnCancel.addActionListener (this);
        btnCancel.setBounds (115, 85, 95, 30);
    public void actionPerformed (ActionEvent e)
        if (e.getSource () == btnLogin) //or the "OK" buton of the loginDialog
            try
                Statement s = conn.createStatement ();
                ResultSet rs = s.executeQuery ("SELECT Password FROM tblAgents WHERE UserName = " + txtUsrName.getText ()); //ORDER BY used to find names easier
                txtPass.setText (rs.getString ("Password"));
                rs.close ();
                s.close ();
            catch (SQLException se)
                JOptionPane.showMessageDialog (this, "There is an error woth your username, please fill it in exactly as assigned.", "Error", JOptionPane.ERROR_MESSAGE);
            //verify user
            String username = txtUsrName.getText ();
            String correctPassword = txtUsrName.getText (); //the correct pass now stored as 'correctPassword'
            if (pasPass.getText ().equals (correctPassword))
                loggedIn = true;
            else
                JOptionPane.showMessageDialog (this, "You are not logged in, or your username does not exist or your password is not correct.", "Error", JOptionPane.ERROR_MESSAGE);
            //Finally checks if logged in and open new window
            if (loggedIn)
            {                new MainHome ();            }
        else if (e.getSource () == btnCancel)
            dispose ();
        }    } }

Similar Messages

  • Can't change database entries

    There is a number of entries in my iTunes database that are reset to their first version when I click on them to play them, e.g., when I have entered "Song no.1" as the name and later decide to change that into "Song no.2", the entry will be reset to "Song no.1" when I click on the title to play it. Strangely, this happens only with some of my entries, whereas others can be changed without problems, and as far as I can tell, it concerns only the fields "Name", "Album", and "Genre".
    This has been a long-standing bug in iTunes (10.5.1) I currently have , and Apple don't seem to care. Is there any fix/workaround for it?
    Thanks,
    Tom

    Yes, either via the menu or via the keyboard shortcut Command-I. Then you have this window opening with a number of buttons at the top ("Summary", "Info",...). When you select "Info", you get the mask to enter information about the title, (Name, Composer, etc.), and that's what I edited. Pressing "Ok" after the changes then changes the entry, but when the title is played at some point thereafter (be it minutes or weeks later), it is reset. I have checked the xml version of the database, which is human-readable, and observe that the change is recorded there as well, and after playing the song at some point later, it is also reset to the previous value.

  • Change database entry through RFC

    how I can change my database entry from RFC by one field as a importing parameter
    please help me out
    Moderator message : Not enough re-search before posting. Thread locked.
    Edited by: Vinod Kumar on Oct 22, 2011 11:15 PM

    close

  • Since the last software update for mountain lion I am having a problem when moving screenshots to trash. Now a Finder box appears saying finder wants to make changes and I have to enter my password for every action.

    Since the last software update for mountain lion, I am having a problem when trying to remove any screenshots to the trash. A box appears saying "Finder wants to make changes. Type your password to allow this"
    I have checked Finder Preferences and cannot find any box that I can 'UNTICK' to resolve this. I sometimes take a lot of screenshots when I am researching something and now find I have to enter my password for every screenshot to be removed to trash.
    Anyone got a solution please, Thanks

    Have you looked at the previous discussions listed on the right side of this page under the heading "More Like This"?

  • Keyboard layout has changed and i can't enter the password

    I was cleaning the keyboard but forgot to turn it off before doing so.  Now i can't access my computer!  I have two accounts. one for the children and one for myself! I logged out of the children's account before i started cleaning it!  I could've forgotten one of the passwords but I am sure i the kids have not forgotten theirs too!
    please help?
    Kind Regards

    1     Make sure your Caps Lock isn't on
    2     borrow or buy a basic USB keyboard to enter the passwords & ensure the system is ok

  • How do I change my iCloud Account email?  I keep getting prompted to enter a password associated with an old email account I no longer use. I do not have the password for it.  How do I change my iCloud Account?

    How do I change my iCloud Account email?  I keep getting prompted to enter a password associated with an old email account I no longer use. I do not have the password for it.  How do I change my iCloud Account?

    You can't delete an existing account, you can only choose to stop using it.  It will still be there should you decide to use it again in the future.

  • My computer continually asks me to enter my password for Keychain access. This problem is continuos and I am having trouble with eliminating it. I have changed my password through Security and my Accounts numerous times to no avail.  Is there anythin

    My computer continually asks me to enter my password for Keychain access. This problem is continuos and I am having trouble with eliminating it.
    I have changed my password through Security and my Accounts numerous times to no avail.
    Is there anything I can do other than Resetting the entire computer and re installing all of the software, apps, etc.etc.

    Back up all data before proceeding.
    Launch the Keychain Access application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad and start typing the name.
    Select the login keychain from the list on the left side of the Keychain Access window. If your default keychain has a different name, select that.
    If the lock icon in the top left corner of the window shows that the keychain is locked, click to unlock it. You'll be prompted for the keychain password, which is the same as your login password, unless you've changed it.
    Right-click or control-click the login entry in the list. From the menu that pops up, select
              Change Settings for Keychain "login"
    In the sheet that opens, uncheck both boxes, if not already unchecked.
    From the menu bar, select
              Keychain Access ▹ Preferences... ▹ First Aid
    There are four checkboxes in the window that opens. Check all of them. if they're not already checked. Close the window.
    Select
              Keychain Access ▹ Keychain First Aid
    from the menu bar and repair the keychain. Quit Keychain Access.
    If you use iCloud Keychain, open the iCloud preference pane and uncheck the Keychain box. You'll be prompted to delete the local iCloud keychain. Confirm. Then re-check the box. Follow one of the procedures described in this support article to set up iCloud Keychain on an additional device.

  • My Apple ID was changed.  Yet when I try to update apps I am asked to enter the password for the old IG which will not work and no matter what I do. When I attempt to update apps it still askes for the wrong ID data.

    My Apple ID was changed.  It works fine on my IPad mini, my MAc and in Itunes Store,  Yet when I try to update apps on my IPAD 1 I am asked to enter a password for the old ID user name which appears in the pop up window. When It still askes for the wrong ID data. I have uodated it in settings, and I have logged ontht the account to verify that it still works properly and it does.  I reboot the IPAD and then attempt to update apps again but it still asked for the Old ID password and still shows the old ID username.  The dame thing refuses to recognize my new Apple ID data.  This is making my older IPAD unuseable.

    You cannot change your Apple ID. You can get a new one if you want, but all of your Apps and media are linked to yoru old Apple ID. And no, Apple won't transfer your old ID purchases to yoru new ID.

  • I can't get FaceTime or iMessage to connect, I enter valid password (tested and works for Apple account) and it won't connect. I have checked all settings, upgrades iOS to 8.3 rebooted, changed Apple acount PW still wont connect. My internet connecti

    I can't get FaceTime or iMessage to connect, I enter valid password (tested and works for Apple account) and it won't connect. I have checked all settings, upgrades iOS to 8.3 rebooted, changed Apple acount PW still wont connect. My internet connection is fine Safari works and I can access all sites. I have an iPad 2. Any help on this will be greatly appreciate.  iPad 2, iOS 8.3

    This is an ongoing problem as you will see by searching the forum. 
    Out of curiosity, do you have 2 step verification enabled?  It was recently extended to include iMessage & FaceTime & I'm wondering if it might be causing some of the issues that some users are experiencing.

  • My iphone 3gs will not connect to itunes and it says that I need to do a system restore. It also says that I need to enter my password on the iphone to connect to itunes but I can not do this because the phone is in emergency phone call mode only.

    My iphone 3gs will not connect to itunes and it says that I need to do a system restore. It also says that I need to enter my password on the iphone to connect to itunes but I can not do this because the phone is in emergency phone call mode only.

    Turn your phone off and connect your cable to the computer, but not the device just yet. Start up iTunes. Now, hold down the home button on your phone and plug it in to the cable - don't let go of the button until iTunes tells you it's detected a phone in recovery mode. Now you can restore to factory settings.
    Unfortunately, the data on your phone is already gone if you're seeing the connect to iTunes logo.

  • My imac will not load after I enter my password. The only thing I get is the arrow from my mouse on top of a blank white screen.  Can anyone tell me what this is?  I've restarted and turned off several times.  I left it on in this state for 8 hours and

    My imac will not load after I enter my password. The only thing I get is the arrow from my mouse on top of a blank white screen.  Can anyone tell me what this is?  I've restarted and turned off several times.  I left it on in this state for 8 hours hoping it would reload and work.  No luck.

    Hello KCC4ME,
    You may try booting your Mac in Safe Boot, as it can resolve many issues that may prevent a successful login.
    OS X: What is Safe Boot, Safe Mode?
    http://support.apple.com/kb/HT1564
    If a Safe Boot allows you to successfully log in, you may have issues with one or more login itmes (while the following article is labelled as a Mavericks article, it is viable for earlier versions of the Mac OS, as well).
    OS X Mavericks: If you think you have incompatible login items
    http://support.apple.com/kb/PH14201
    Cheers,
    Allen

  • I have never had to enter a password to access mail. However, recently, I keep being asked for password on my ****** address. Only on my macbook. (which, btw, has a version number the drop down doesn't offer as a choice. I had to putt 9.4)

    I have never had to enter a password to access mail.
    However, recently, I keep being asked for password on my ***** address.
    Only on my macbook. (which, btw, has a version number your drop down doesn't offer as a choice. I had to putt 9.4)
    When I look up the account the "password" is a long string of gobbledygook. Something I would never do.
    But when I attempt to use that pw I still can't get in.
    I have no trouble accessing that email account on my mac mini. Just on the macbook.
    <Edited by Host>

    Maiko,
    I'm confess I'm still trying to get a handle on your problem. You do a fantastic job of describing it ... but I'm just trying to picture it accurately in my head.
    I think, were I in your shoes, I'd begin by looking at what the debug page has to say for the specific destination in which you're interested in fixing. In other words, I'm not clear on where, exactly, this destination points ...
    Destination illinois.edu.1945806043
    Is that your site, or the division within your site that you want to fix? "Normally", you do not need to specify a site handle to get to your site within your transfer CGI ... if you say "uillinois.edu", it's enough to transfer your users to iTunes U ... but every site still has a handle, and you could, if you wanted to, actually specify it in your transfer CGI. For example, this:
    Destination uic.edu.1139051993
    is for my entire site ... it's my site handle. Whereas this:
    Destination uic.edu.1991288441
    is for a division within my site ... but it's impossible to tell the difference between "site" and "division" from just the handle (I mean, if I didn't say "this is a site" and "this is a division", there'd be no way for you to know). So when I look at your creds and permissions on your debug page, I can't quite tell if they give you download access for your site, or for the specific division you want to fix. If you could open the debug page with your division as destination (or confirm that that's what we're looking at), it'd rule out some things.

  • My IMac has stopped seeing the keyboard. I have changed the batteries and the green light comes on saying it is looking to pair with the IMac but without success. I am left with the IMac switched on and I am unable to enter a password.

    I have been using my IMac without a problem when I left it and went back to enter the password the IMac did not see the keyboard. I have changed the batteries and the green light comes up on the keyboard and then starts to flash indicating it is looking for the IMac but nothing happens. I have tried another set of new batteries with the same result. Is there any known problems in this area. The IMac is 5 months old.
    Thank you for any help

    What operating system does your iMac have? (please always post your operating system to prevent confustion).
    If it's pre-Lion you will have to set Mail up manually:
    Entering iCloud email settings manually in Snow Leopard or Leopard
    Entering iCloud email settings manually in Tiger

  • I changed my password on Airport Express and now can't connect in iTunes. It does not ask for password ,I just see trying to connect and it fails. How do I enter new password in iTunes when it just keeps trying to connect ?

    When I select the Airport Express as Remote Speaker in Itunes I just see trying to connect and it can't connect.
    I changed my password on the Airport and I don't see where I can put in the new password in Itunes.
    This problem is on my Imac. On my Mac Pro a window came up asking for password to connect because it was the first time.
    I can connect on the Mac Pro but not my Imac.

    Update on my problem connecting in Itunes with my Airport Express. Not sure if anything I tried made a difference
    but I finally got the Pop up window saying this device requires a Password. I entered the password and I can once again use the Airport Express as a remote speaker.

  • I changed by apple id and password on apple web site but when I try to sign in on my touch it asks me to enter the password for my old apple id, how do i get icloud to recongnize my new id?

    I changed my AppleID and password on the Apple web site but when I try to sign in on my touch it asks me to enter the password for my old Apple ID, how do i get ICloud to recognize my new ID?

    Hi appledapple1964,
    After changing your Apple ID information, you may need to manually sign out and sign back in on your devices so that they may recognize the update. You may find the following article helpful:
    iOS: Changing the signed-in iTunes Store Apple ID account
    http://support.apple.com/kb/ht1311
    Regards,
    - Brenden

Maybe you are looking for