I am trying to connect to mysql database (as part of the Vertrigo server) on my windows 7 pc, but it keeps throw me the "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver".
Following is my code :
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 class ShippingCompany {
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();
}
}
should be