gpt4 book ai didi

java.lang.ClassNotFoundException : com. mysql.jdbc.Driver Vertrigo 服务器 eclipse

转载 作者:行者123 更新时间:2023-11-29 00:29:50 25 4
gpt4 key购买 nike

<分区>

我正在尝试连接到我的 Windows 7 PC 上的 mysql 数据库(作为 Vertrigo 服务器的一部分),但它一直向我抛出“java.lang.ClassNotFoundException:com.mysql.jdbc.Driver”。

以下是我的代码:

import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import java.util.LinkedList;import java.util.List;

公共(public)类航运公司{

private Connection conn;
private Statement stmt;
private List<Journey> journeyList;
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String DB_URL = "jdbc:mysql://172.16.127.38:3306/testRestricted";

public ShippingCompany(String dbUser, String dbPassword) throws Exception {
journeyList = new ArrayList<Journey>();
try {
Class.forName(DRIVER);
conn = DriverManager.getConnection(DB_URL, dbUser, dbPassword);
stmt = conn.createStatement();
} catch (SQLException e) {
System.out.println("SQL Exception:" + e);
}
}

public List<String> readAllPorts() throws SQLException{
List<String> allPorts = new ArrayList<String>();
String command = "SELECT * FROM Ports";
ResultSet rs = stmt.executeQuery(command);
while (rs.next()) { // database name string is in first column of result set
allPorts.add(rs.getString(2));
//In command concole, print out all ports
System.out.println(rs.getString(2));
}
return allPorts;
}

public List<Journey> getAllJourneys(String startPort, String startDate, String endPort){
return new LinkedList<Journey>();
}

private void findPaths(Journey journey, String endPort){

}

public void Close(){

}

public static void main(String[] args) throws Exception{
//TODO : entry point of the program
ShippingCompany sc = new ShippingCompany("root", "vertrigo");
sc.readAllPorts();
}

} enter image description here应该是

enter image description here

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