Reputation: 1265
I use database.properties to save my database information. However, it pop up this error, every time I run the code. I don't know which part of the database is wrong. Please help!
host: 127.0.0.1
port: 3306
database: spider
username: root
password: !QAZxsw2
driver: com.mysql.cj.jdbc.Driver
drivertype: MYSQL
ERROR Database:40 - java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Failed to parse the host:port pair '127.0.0.1:3306;databaseName=spider;user=root;password=!QAZxsw2;serverTimezone=UTC&'.
Upvotes: 0
Views: 10893
Reputation: 108937
You seem to be using SQL Server JDBC driver syntax for the URL, while you are using the MySQL JDBC driver.
See MySQL Connector/J 8, Connection URL Syntax, the URL to connect to MySQL would be:
jdbc:mysql://127.0.0.1:3306/spider?user=root&password=!QAZxsw2&serverTimezone=UTC
Note that I also removed the &
you had, which has no place in a URL, unless you are putting it in XML and want to escape the &
between key-value pairs.
Given the syntax of JDBC URLs is undefined, except for the jdbc:<sub-protocol>:
prefix, you cannot try to dynamically construct it like you are doing and expect it to work on different drivers. Each driver has their own syntax, and although there is considerable overlap in syntax, each has their own idiosyncrasies (if not outright outlandish syntax). Instead, use a single property for the entire URL, or use a driver-specific strategy.
Upvotes: 1
Reputation: 1265
After I post this question, I found out that my connection string was wrong. jdbc:mysql://localhost:%s/%s?serverTimezone=UTC&"+"user=%s&password=%s
It should be like that url pattern of mysql.
Upvotes: 0