Reputation: 21
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());
}
}
Upvotes: 0
Views: 120
Reputation: 46408
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);
Upvotes: 1