gpt4 book ai didi

java - 格式错误的数据库 URL,无法解析主要 URL 部分

转载 作者:可可西里 更新时间:2023-11-01 08:02:29 26 4
gpt4 key购买 nike

package miniproject;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Mysql_connection {

private Connection con=null;
private Statement st=null;
private ResultSet res=null;
public Mysql_connection() {
try{
//Class.forName("com.mysql.jdbc.Driver");

con=DriverManager.getConnection("jdbc:mysql:‪//localhost:3306/miniprojectdb","root","");
st=con.createStatement();

}catch(SQLException e)
{
System.out.println("SQLException: "+ e.getMessage());
System.out.println("SQLState: "+ e.getSQLState());
System.out.println("VendorError"+ e.getErrorCode());
}
}
public void Data(){
try{
String query="select * from produit";
res=st.executeQuery(query);
System.out.println("=========================");
while(res.next()){
int a=res.getInt(1);
String b=res.getString(2);
int c=res.getInt(3);
System.out.println("ProdID:"+a+" "+"ProdNom:"+b+" "+"Prix/Tonne:"+c);
}
}catch(Exception e){
System.out.println(e);
}
}

}

我收到这个错误:

SQLException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections.

SQLState: 08001

VendorError0

我正在使用这个 (C:\Users\ABDOU NASSER\Desktop\mysql-connector-java-8.0.11\mysql-connector-java-8.0.11.jar)最后的 eclipse 版本 2018并作为数据库 XAMPP (MySQL)

enter image description here enter image description here enter image description here

最佳答案

在您的 JDBC URL 中,mysql://localhost 之间有一个不可见的字符。你可以在这里查看:

https://www.soscisurvey.de/tools/view-chars.php

这将字符串显示为:

jdbc:mysql:‪U+202A//localhost:3306/miniprojectdb

这个U+202A字符是LEFT-TO-RIGHT EMBEDDING .

关于java - 格式错误的数据库 URL,无法解析主要 URL 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50311481/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com