Yousaf Yousaf - 3 months ago 20
Java Question

Getting password from JTextField using PrepareStatement object

I am creating a simple login application in java netbeans. I have made a connection with a MS-Access database in which i am storing the usernames and their passwords.

Suppose is i want to get text from a JTextField, i would use an object of PrepareStatement for the query. For Example 'ps' is the object of PrepareStatement, now to get text from JTextField i write statement,

ps.setString(1, jTextField1.getText());

As JPasswordField returns a character array, how can i get password from the JPasswordField using PrepareStatement object 'ps' ?


Just create a new String from the char[].

ps.setString(1, new String(jPasswordField.getPassword()));