Link to home
Create AccountLog in
Avatar of komlaaa
komlaaa

asked on

connectin excel database using password

Hi,

Below is how i am connecting to excel database, but i would like to force the user to enter password.
How can i for instance have a diaglog pop up and then check for that the right password and username?

==============  piece of code =============
public void parseDatabase()
{
        try
        {
            String  filename = openFile();
           
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            // set this to a MS Excel DB you have on your machine
            System.out.println("The File: " + filename);
            // now we can get the connection from the DriverManager to ExcelDB
            String excelDatabase = "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=";
            excelDatabase+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
         
            excelCon = DriverManager.getConnection( excelDatabase ,"","");
   .....
SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
>> JOptionPane.showInputDialog(frame, "Password?");

However, this would show the password on the screen while the user types it :) I would suggest using a JDialog and adding a JPasswordField to it.
Avatar of komlaaa
komlaaa

ASKER

>>JPasswordField textfield = new JPasswordField("Initial Text");
 >>   textfield.setEchoChar('#');
  >>  textfield.addActionListener(actionListener);

1.)With this implementation, do u think the application will hang untill the user press Enter
as it will happen with JOptionPane?

>>When the user hits RETURN, the text field fires an action event
2.) What will this action event do? Retrieve the password and check for it?

ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
>> What will this action event do? Retrieve the password and check for it?

Otherwise, if you want, you can also register a handler for this event and do the same thing which you do on the click of the OK button. You can fire the actionPerformed () method for the button if you want or use a common method and call it in both event-handlers. But don't bother about it right now ;-)
Avatar of komlaaa

ASKER

i will get back to u