Search code examples
javamysqlscalanumberformatexception

Get java.lang.NumberFormatException for DriverManager.getConnection


I am writing an application in Scala. I am trying to connect to mysql database. To do that I am using java.sql.DriverManager. But I am getting a NumberFormatException

Here is my code.

val user = "root"
val password = "rootpassword"
val url = "jdbc:mysql://root:rootpassword@localhost:3306/database_name";

Class.forName("com.mysql.jdbc.Driver")
val connection: Connection = DriverManager.getConnection(url, user, password)

Here is the error I am getting.

[error] application - Cannot load connection class because of underlying exception: 'java.lang.NumberFormatException: For input string: "firstlook@localhost:3306"'.


Solution

  • You have to remove the user and password from the url:

    val url = "jdbc:mysql://localhost:3306/database_name";