Problems setting up username & password for SQL

Due to the outstanding advice I recieved from this excellent forum, I have managed to overcome my first problem with declaring a new Class.
This leads me to request help with my next biggest problem:
Setting up a user GUI that takes a "username" & "password" that will be used to access a password protected database.
I am a simple bloke, with simple thought processes, so please, go easy on me...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class DBQuery1 {
     String username = "" , password = "";
     public static void main(String[] arguments) {
          PassDB UPass = new PassDB();
          String data = "jdbc:odbc:JavaTestDataBase";
          try {
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               Connection conn = DriverManager.getConnection(data, "" + username, "" + password);
               Statement st = conn.createStatement();
               ResultSet rec = st.executeQuery(
                    "SELECT Title, ContactID, First, Last, Dear FROM Contacts "
                    + "WHERE (Title='Mr') ORDER BY ContactID");
          /*     ResultSet rec2 = st.executeQuery(
                    "SELECT Subject, ContactID FROM Calls "
                    + "WHERE (Subject Is Not Null) ORDER BY ContactID");
          System.out.println("\nFirst Name\tSurname\t\tNick Name\t\tSubject\n");
          while(rec.next()) {
               System.out.println(rec.getString(3) + "\t\t" + rec.getString(4) + "\t\t" + rec.getString(5) /* + rec2.getString(1) */ );
          st.close();
          catch (SQLException s) {
               System.out.println("SQL Error: " + s.toString() + " " + s.getErrorCode() + " " + s.getSQLState());
          catch (Exception e) {
               System.out.println("Error: " + e.toString() + e.getMessage());
class PassDB extends javax.swing.JFrame implements ActionListener {
     String username = "", password = "";
     JTextField uname = new JTextField(10);
     JTextField pword = new JTextField(10);
     // JPasswordField pword = new JTextField(10);
     PassDB() {
          super("duBe's database logon");
          setSize(220, 160);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          JPanel pane = new JPanel();
          JLabel unameLabel = new JLabel ("Username: ");
          JLabel pwordLabel = new JLabel ("Password: ");
          JButton submit = new JButton("OK");
          submit.addActionListener(this);
          pane.add(unameLabel);
          pane.add(uname);
          pane.add(pwordLabel);
          pane.add(pword);
          pane.add(submit);
          setContentPane(pane);
          setVisible(true);
     public void actionPerformed(ActionEvent evt) {
          PassDB clicked = (PassDB)evt.getSource();
          username = uname.getText();
          password = pword.getText();
This code generates two errors, stating:
C:\Java_progs>javac DBQuery1.java
DBQuery1.java:14: non-static variable username cannot be referenced from a static context
Connection conn = DriverManager.getConnection(data, "" +
username, "" + password);
^
DBQuery1.java:14: non-static variable password cannot be referenced from a static context
Connection conn = DriverManager.getConnection(data, "" +
username, "" + password);
                ^
2 errors*****************************
The code works when I remove the reference to the variables "username" & "password" in Connection "conn" call & replace them with the actual username & password, but this is not exactly what I was after. I was hoping to make the program responsive to each individual user, not set in code.
I also would like to make the program pause after the call in "main" to "PassDB" to wait for "PassDB" to exit before continuing.
I would also like to make "PassDB" destroy itself after the "OK" button is pressed & the "username" & "password" set.
If that isn't enough for you, I would really like the program to search 2 different database tables, return their values & compare them to be sure that they are the same.
When I try & search 2 different tables, as in:
ResultSet rec = st.executeQuery(
                    "SELECT Title, ContactID, First, Last, Dear FROM Contacts "
                    + "WHERE (Title='Mr') ORDER BY ContactID");
               ResultSet rec2 = st.executeQuery(
                    "SELECT Subject, ContactID FROM Calls "
                    + "WHERE (Subject Is Not Null) ORDER BY ContactID")javac tells me that "ResultSet" is set to null 0
As always, I am extremely appreciative of any assistance you are able to offer.
Kind regards
duBedat
[email protected]

This is where I'm at now:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class DBQuery {
     static String username = "" ;
     static String password = "" ;
     public static void main(String[] arguments) {
     PassDB UPass = new PassDB();
     String data = "jdbc:odbc:JavaTestDataBase";
     try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          Connection conn = DriverManager.getConnection(data, "" + DBQuery.username, "" + DBQuery.password);
          Statement st = conn.createStatement();
          ResultSet rec = st.executeQuery(
          "SELECT Title, ContactID, First, Last, Dear FROM Contacts "
          + "WHERE (Title='Mr') ORDER BY ContactID");
          /*     ResultSet rec2 = st.executeQuery(
               "SELECT Subject, ContactID FROM Calls "
               + "WHERE (Subject Is Not Null) ORDER BY ContactID");
          System.out.println("\nFirst Name\tSurname\t\tNick Name\t\tSubject\n");
          while(rec.next()) {
               System.out.println(rec.getString(3) + "\t\t" + rec.getString(4) + "\t\t" + rec.getString(5) /* + rec2.getString(1) */ );
          st.close();
     catch (SQLException s) {
          System.out.println("SQL Error: " + s.toString() + " " + s.getErrorCode() + " " + s.getSQLState());
     catch (Exception e) {
          System.out.println("Error: " + e.toString() + e.getMessage());
class PassDB extends javax.swing.JFrame implements ActionListener {
     static boolean getOut = false;
     JTextField uname = new JTextField(10);
     JTextField pword = new JTextField(10);
     // JPasswordField pword = new JTextField(10);
     public PassDB() {
          super("duBe's database logon");
          setSize(220, 160);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          JPanel pane = new JPanel();          
          JLabel unameLabel = new JLabel ("Username: ");
          JLabel pwordLabel = new JLabel ("Password: ");
          JButton submit = new JButton("OK");
          submit.addActionListener(this);
          pane.add(unameLabel);
          pane.add(uname);
          pane.add(pwordLabel);
          pane.add(pword);
          pane.add(submit);
          setContentPane(pane);
          while(getOut == false)
               setVisible(true);                         
     public void actionPerformed(ActionEvent evt) {
          PassDB clicked = (PassDB)evt.getSource();
          DBQuery.username = uname.getText();
          DBQuery.password = pword.getText();
          getOut = true;               
}          Any advice is greatly appreciated
duBe

Similar Messages

  • Setting the username & password for the plain http adapter.

    Hi,
    When i am passing in an HTTP request into the integration engine's plain_http adapter url, i am required to give a username and a password for authentication.
    Is it possible to set this username and password globally some where, to avoid this to be given again for each message?
    The requirement is like, all http messages from our partners will be routed through a proxy in the DMZ which would have an authentication and we donot want the XI user credentials to be given again.
    Thanks & Regards,
    Renjith.

    If you want to just test http adapter use the code by stefan grube in the following thread.
    /message/266750#266750 [original link is broken]
    Thanks for the points
    regards
    SKM

  • Got premium with Facebook login - how do i set a username/password for regular login

    Hello all,i got the student premium whilest logged in with facebook, but i would like to set a usename/password to log in 'normally'. how can i do that?thank you!

    Hey there , welcome to the community!
    I apologize for the late reply. The workaround for this would be to create a new account. If you contact the accounts team through the online contact form they can set you up with a new account and transfer over all your content. If you receive an automated reply directing you back to the community, just reply to it and you will be connect with an agent that can assist you.

  • What are the defaul username and password for SQL Plus ?

    hello, what are the defaul username and password for SQL Plus ? i'm using the client 11.2.0.1

    You'll need to download the full database installation files for the platform you are using. They are two .zip files, about 2.2 gig total.
    I'm not going to give you the link because you should be able to find it easily. You have to read and accept the license agreement anyway.
    When you install it, you'll be given several options about the type of database you want.
    But before you install anything, you should read the installation manual for your platform.

  • Setting up a password for a switch web interface?

    Hi,
    I am trying to figure out how to set up a username/password for this switch I have.
    it is a: Cisco WS-C2924M-XL
    It seems to be easy but I couldn't find out how to do it so far.
    Any help would be appreciated.. i just started working with this. thanks!

    Hi!
    Are you trying to enable and set username/password for accessing switch through the web-interface? I hope I understood you correctly.
    Firstly you need to enable the switch for web-interface.
    Enter this command --> ip http-server
    Then you can login using the username [admin] and the enable password.
    If you want to set some other username for this purpose, then enter this command --> username
    Then you can login using the username and the enable password. By default only level 15 access is enabled for the web-interface.
    For a lil more have a look at the following URL --> http://www.cisco.com/en/US/tech/tk59/technologies_configuration_example09186a0080178a51.shtml#local
    Hope this helps...
    Regards,
    AbhisheK
    Please rate all helpful posts!!!

  • HT1316 i have set up a password for my iphone 3gs apparantly i forgot the password..what's the redemy?HELP!

    i have set up a password for my iphone 3gs apparantly i forgot the password..what's the redemy?HELP!

    Sig, I appreciate you trying to be helpful. I have no idea what issues you were having or what issue exactly pgrounds has been having. Your assumption that everyone's set up is the same as yours is false however. There are many many documented WiFi issues that are a result of Lion installs. Many have been solved by 10.7.1 and 10.7.2. Others have been solved by a large variety of work arounds. Others have not had their issues solved yet.
    I am one of those. I have an IT background, and I spent the better of five hours digging up workarounds and attempting all of them. For the benefit oh anyone who is having similar issues, I have posted links to all of those workarounds here. None of them worked in my case, but hopefully they will help pgrounds or others.
    So, once again, if you have a new idea, I'd love to here it. But if it has already been posted in one of these links, it's not helpful, let it go.
    http://osxdaily.com/2011/07/22/wifi-dropping-in-os-x-lion-fixes/
    http://osxdaily.com/2011/11/06/lion-wi-fi-problems-solution-mac/
    http://blog.chron.com/techblog/2011/09/want-to-really-repair-permissions-on-your -mac-try-this/

  • My laptop (HP Pavilion) will not allow me to upgrade or download Firefox without logging in as Administrator, and I don't recall ever setting up a password for Administrator...I'm the only user of the laptop. How can I get around this?

    I was trying to upgrade to the newest version of Firefox, and when I downloaded it, and clicked on run, it took me to a login box, where I had to choose whether to continue as current user or login as Administrator. When I clicked on continue as current user, nothing happened. When I tried logging on as Administrator, I used all the passwords I could think of that I use and nothing was accepted. Id on't recall ever setting up a password for Adminstrator on this computer, so I don't know what to do. I even deleted the older version of Firefox thinking that might help, but it didn't work either, and now I don't even have that! Help!

    What iPhone do you have? You can check in settings>>general>> about.
    If you have a 3G you cannot update beyond iOS 4.2.1. The 3G is over 4 years old an was discontinued over 2 1/2 years ago. You need the latest ios to run the latest versions of some apps. If you have a 3GS you can update.
    If your phone is not responding, reset it by pressing and holding down both the home button ad lock/ sleep button simultaneously until the Apple logo appears.

  • Help!!!!!! OS X wants to use the "local items" keychain. Please enter password. I have tried every password that I know of. Nothing works! I haven't even set up a password for this

    Help!!!!!! OS X wants to use the "local items" keychain. Please enter password. I have tried every password that I know of. Nothing works! I haven't even set up a password for this

  • HT201270 i have just updated my old 3GS and now when i am on restore the window is comming up and asking for a password. i have not set up a password for restore, please help how i can restore my date???

    i have just updated my old 3GS and now when i am on restore the window is comming up and asking for a password. i have not set up a password for restore, please help how i can restore my date???

    capriz wrote:
    i have just updated my old 3GS ...
    To what... iOS 7 is Not supported on the 3 GS

  • Long story short i need to set up a password for my links...

    long story short i need to set up a password for my linksys wireless router... i tried go to linksys' website link  i went ahead and set up a password using instructions from the link above...went to http://192.168.1.1/...clicked on admin tab and set up password... to test out my password i turned on/off my wireless connection on my macbook. when i turned it back on and selected the linksys wireless connection from the dropdown menu on my macbook it did NOT prompt me for a password? what am i doing wrong? why isnt it asking me for a password?
    Message Edited by OnnagokorO on 11-27-2007 11:53 PM

    The password you have changed is the password which protects the access to the web interface of the router. In other words, you must know this password to make changes to the configuration of the router. It is not the encryption key for wireless security. Wireless security is configured on the Wireless Security tab.
    For some more background see here.

  • I want to erase the automatic sign-in of username & password for facebook, because firefox always rfemembers my username & password. How will i disable it? please help.. thanks

    How will i disable the auto sign in of my username & password for facebook?

    If you saved the password in Firefox, you can clear that here:
    orange Firefox button > Options > Security > "Saved Passwords"
    ''or''
    Tools menu > Options > Security > "Saved Passwords"
    It's also possible that you have a cookie that keeps you logged in, but in that case, signing off from Facebook should end your session.

  • Setting Up A Password for Mac Mini

    Hello
    Due to Lion causing an issue with my wifi I had to downgrade to Snow Leopard which meant all my settings  etc were changed.  How do I set up a password for changing things on my computer and locking up  after changes
    Thank you
    rachealfromva

    Try powering it down, & if they/you didn't setup Firmware Protection Password, or FileVault, then try this...
    Reset OS X Password Without an OS X CD...
    http://theappleblog.com/2008/06/22/reset-os-x-password-without-an-os-x-cd/
    Admin Hack...
    http://www.hackmac.org/?q=node/4
    Starts up like the first time you buy a new Mac, but after filling in all that info again, you should have access to the computer and the other Users & files will still be there... give the new User a different name than an existing one.

  • I have set a strong password for my iPhone 5s, now I want to get rid of it and set a numeric 4 digit password. How to do that ??

    I have set a strong password for my iPhone 5s, now I want to get rid of it and set a numeric 4 digit password. How to do that ??

    go to settings>general>passcode lock and "enable simple passcode"

  • How to set the connection parameters for SQL

    How to set the connection parameters for SQL to access the MS Access database
    Attachments:
    Quick_SQL.vi ‏21 KB
    Doc1.doc ‏45 KB
    db1.mdb ‏112 KB

    Right-click the WINDOWS desktop, choose New->Microsoft Data Link. That will bring up a dialog that allows you to configure and test your database connection. You might connect to the Access database via ODBC or directly via Jet Engine. The Jet Enginge saves you the trouble of creating an ODBC connection on your PC. After you leave the dialog, the "data link" will show up on your desktop as text file. Open it and copy-paste the connection string to your VI.
    This webpage is an excellent resource for connection strings: http://www.able-consulting.com/ADO_Conn.htm
    If your application requires users to change the database connection at runtime, you can also include the dialog via ActiveX (MSDASC.IDataSourceLocator).

  • Username/Password for Examples App

    This is probably a stupid question, but does anyone know the Username/Password for Vikas's Examples Application? I downloaded and imported it into my workspace but when I run it, I cannot log in!!!

    Hello,
    Are you speaking about this app:? http://apex.oracle.com/pls/otn/f?p=24317:500:1182459246082825
    You can send Vikas always a mail, he has contact info on there.
    I guess you asked that question also in another thread (chart in report)?
    Regards,
    Dimitri
    -- http://dgielis.blogspot.com/
    -- http://apex-evangelists.com/
    -- http://apexblogs.info/

Maybe you are looking for

  • DVD-ROM not working (S1800-804)

    Suddenly the DVD stopped working. The indicator lamp is turned on constantly. The dvd seems to initiate when putting in a disc but doesnt actually read any cds or dvds. Nothing happens. Anybody that recognize this behaviour, or what do? (BIOS 2.20)

  • Burning disk Problems. Toast/Compressor

    So I'm burning a movie I made onto a DVD from a prores 422 quicktime file using toast and/or compressor and the disk is always messed up. When burning with compressor the disk gets stuck about halfway through playback, after the burn is complete. I c

  • Determining which user has acquired a task

    I'm trying to determine which, if any, user has acquired a human task. I'm working with the Java API to interface with the SOA server. I can't find any APIs which might allow me to do this. Does anyone know if this is possible?

  • Render on internal HD same speed as USB - make sense?

    I cannot figure this out. I'm using MacBook unibody that is a core 2 duo 2.0 ghz w/ 2GB of RAM, and a 160GB 5400 HD. I wanted to speed up the render time qnd was thinking that if added another internal 7200 HD as a dedicated scratch disk that it woul

  • How do I resize iPhoto images for uploading?