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;
}
}
我得到的錯誤用sql連接java。錯誤
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: 無法加載,因爲底層異常的連接類: 「java.lang.NumberFormatException:對於輸入字符串: 「3306:圖鑑」」。
我只是想看看我是否連接到數據庫,以便我可以在我的表中輸入數據。
您的網址不正確。它應該是'jdbc:mysql:// localhost:3306/Pokedex' – Bunti