到目前为止,我试图像这样连接数据库:
package database;
import java.sql.Connection;
import java.sql.DriverManager;
public class Main {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
getConnection();
}
public static Connection getConnection() throws Exception{
try {
String driver = "com.mysql.cj.jdbc.Driver";
String url = "jdbc:sqlserver://myLaptopName//SQLEXPRESS";
String username = "myUserName";
String password = "myPassword";
Class.forName(driver).newInstance();
Connection connect = DriverManager.getConnection(url, username, password);
System.out.println(connect);
System.out.println("Connected");
return connect;
} catch (Exception e) {
// TODO: handle exception
System.out.println("something is wrong");
e.printStackTrace();
}
return null;
}
}
我在日食中遇到的错误就是这个。
java.sql.SQLNonTransientConnectionException: Cannot load connection class
because of underlying exception:com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections
。
这也是。
Caused by: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections.
我知道我做错了什么,这就是我想知道的。任何帮助,将不胜感激。我尝试但无法找到可以解决此问题的解决方案。 任何帮助将不胜感激的人!