I don't know why but this line gives me an error. I'm first making a few private strings, host, port, database, user and password. Then I'm setting those strings in the constructor.
Connection conn = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?user=" + user + "&password=" + password);
This is the error message that I get:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Cannot load connection class because of underlying exception: 'java.lang.Number FormatException: For input string: "null"'.
What did I do wrong here?
The most likely cause is that one of your parameters is null. Probably port, since an attempt is made to convert it to a number.
Unless you are using a non default port (the default being 3306), you can just omit the port :
Connection conn = DriverManager.getConnection("jdbc:mysql://" + host + "/" + database + "?user=" + user + "&password=" + password);
My guess, without seeing more code, is that port is null.
When you pass the string to the getConnection() method, it tries to parse out the port as a number. The when you concatenate a null value to a String, it appends 'null'. Now your string looks like jdbc:mysql://examplehost:null. Thus the java.lang.Number FormatException: For input string: "null".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With