0

This is a jFrame to connect to the database and this is in the button connect. My issue is in the passwordField NetBeans make me do a char[], but my .getConnection not let me insert the char[] ERROR: "no suitable method found for getConnection(String,String,char[])". So I will change to String right? So when I change and run the jFrame said access denied. when I start doing the System.out.println(l) " Give me the right answer" Like this: "Alex". But when I do the System.out.println(password) "Give me the Array spaces and not the value" Like this: jdbc:mysql://localhost/home inventory root [C@5be5ab68 <--- Array space . What I doing wrong?

 try {
    Class.forName("org.gjt.mm.mysql.Driver"); //Load the driver

    String host = "jdbc:mysql://"+tServerHost.getText()+"/"+tSchema.getText();

        String uName = tUsername.getText();
        char[] l =  pPassword.getPassword();
        System.out.println(l);
        String password= l.toString();

        System.out.println(host+uName+password);
        con = DriverManager.getConnection(host, uName, password);
        System.out.println(host+uName+password);
    } catch (SQLException | ClassNotFoundException ex) {

    JOptionPane.showMessageDialog(this, ex.getMessage());
    } 
}
0

1 Answer 1

1

To convert an char[] to a string just create a new String with passing char[] as an argument to the constructor. new String(char[])

char[] l = pPassword.getPassword();
String s = new String(l);
System.out.println(s);
Sign up to request clarification or add additional context in comments.

1 Comment

Work very good I was doing this before: String s = new String(char[l]); I don't what I was thinking. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.