?
Solved

connectin excel database using password

Posted on 2005-02-25
8
Medium Priority
?
261 Views
Last Modified: 2010-03-31
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 ,"","");
   .....
0
Comment
Question by:komlaaa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 92

Assisted Solution

by:objects
objects earned 200 total points
ID: 13408824
String password = JOptionPane.showInputDialog(frame, "Password?");
0
 
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:komlaaa
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?

0
 
LVL 30

Accepted Solution

by:
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 () ).
0
 
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 ;-)
0
 

Author Comment

by:komlaaa
ID: 13411321
i will get back to u
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues undeā€¦
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

765 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