0
package pokemon;
import java.sql.Connection;
import java.sql.DriverManager;


public class Main {

public static void main(String[] args) throws Exception {

    getConnection();

}
public static Connection getConnection() throws Exception{
    try{
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306:Pokedex";
        String username = "test";
        String password = "password";
        Class.forName(driver);

        Connection conn =      DriverManager.getConnection(url,username,password);  
        System.out.println("Connected");
        return conn;            
    } catch(Exception e){System.out.println(e);}


    return null;
}
}

I get the error

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Cannot load connection class because of underlying exception: 'java.lang.NumberFormatException: For input string: "3306:Pokedex"'.

I'm simply trying to see if I'm connected to the database so that I can enter data in my tables.

1
  • 1
    Your url is incorrect. It should be jdbc:mysql://localhost:3306/Pokedex Commented Mar 8, 2016 at 4:49

2 Answers 2

1

You are write wrong url. plz Replace it with this line

String url = "jdbc:mysql://localhost:3306/Pokedex";

https://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-connect-drivermanager.html

Sign up to request clarification or add additional context in comments.

Comments

1

Your database URL is incorrect. It needs to be

jdbc:mysql://localhost:3306/Pokedex

You would use a JDBC connection pool whenever possible unless you have a very basic application.

1 Comment

Thank you very much!! That did indeed fix it.

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.