I'm trying to hook up mysql driver in Eclipse IDE but keep getting error message, "Driver not found" here is my code. I went though and added the driver under the ClassPath but it didn't work. I have all the imports I think I need but the driver still isn't being found. Database.java file
package model;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class Database {
private List<Person> people;
public Database() {
people = new LinkedList<Person>();
}
public void connect() throws Exception {
final String driver = "com.mysql.jbdc.Driver";
try {
Class.forName(driver);
System.out.println("Driver loaded!");
} catch (ClassNotFoundException e) {
throw new Exception("Driver not found");
}
String url = "jbdc:mysql://localhost:3306/swingtest";
Connection con = DriverManager.getConnection(url, "root", "root");
}
public void disconnect() {
}
public void addPerson(Person person) {
people.add(person);
}
public void removePerson(int index) {
people.remove(index);
}
public List<Person> getPeople() {
return Collections.unmodifiableList(people);
}
public void saveToFile(File file) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(fos);
Person[] persons = people.toArray(new Person[people.size()]);
oos.writeObject(persons);
oos.close();
}
public void loadFromFile(File file) throws IOException {
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
try {
Person[] persons = (Person[])ois.readObject();
people.clear();
people.addAll(Arrays.asList(persons));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
ois.close();
}
}
TestDatabase.java file
import model.Database;
public class TestDatabase {
public static void main(String[] args) {
System.out.println("Running database test");
Database db = new Database();
try {
db.connect();
} catch (Exception e) {
e.printStackTrace();
}
db.disconnect();
}
}