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.od bc.JdbcOdb cDriver");
// 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={Microso ft Excel Driver (*.xls)};DBQ=";
excelDatabase+= filename.trim() + ";DriverID=22;READONLY=tru e}"; // add on to the end
excelCon = DriverManager.getConnectio n( excelDatabase ,"","");
.....
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.od
// 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={Microso
excelDatabase+= filename.trim() + ";DriverID=22;READONLY=tru
excelCon = DriverManager.getConnectio
.....
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
>> JOptionPane.showInputDialo g(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.
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.
ASKER
>>JPasswordField textfield = new JPasswordField("Initial Text");
>> textfield.setEchoChar('#') ;
>> textfield.addActionListene r(actionLi stener);
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?
>> textfield.setEchoChar('#')
>> textfield.addActionListene
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
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 ;-)
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 ;-)
ASKER
i will get back to u