Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


connectin excel database using password

Posted on 2005-02-25
Medium Priority
Last Modified: 2010-03-31

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()
            String  filename = openFile();
            // 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 ,"","");
Question by:komlaaa
  • 4
  • 2
  • 2
LVL 92

Assisted Solution

objects earned 200 total points
ID: 13408824
String password = JOptionPane.showInputDialog(frame, "Password?");
LVL 30

Expert Comment

by:Mayank S
ID: 13409779
>> 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.
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 13411116
>>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?

LVL 30

Accepted Solution

Mayank S earned 800 total points
ID: 13411139
>> With this implementation, do u think the application will hang untill the user press Enter

Yes, you can make the JDialog modal by specifying its parent (which will be your JFrame or whatever you have), and specify the modal parameter as true in its constructor.

JDialog dialog = new JDialog ( parentJFrame, true ) ;

Set the size for it, add the text-field and an OK button, and then show the JDialog.

>> What will this action event do? Retrieve the password and check for it?

Its not necessary for you to do that. You can do away with the textfield.addActionListener () part. You can simply write whatever you want to on click of the OK button in the JDialog. For example, on click of the OK button, you can close the JDialog and pass the password entered by the user in some variable (you can access what the user entered through new String ( textfield.getPassword () ).
LVL 30

Expert Comment

by:Mayank S
ID: 13411141
>> 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 ;-)

Author Comment

ID: 13411321
i will get back to u

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question