I'm new to databases but I have successfully set up a MySQL server on a Linux machine I have here. I can do MySQL things in the terminal and it works as expected. Now I'm trying to add the dependencies to my Java project in Eclipse so that I can query that database. I have added mysql-connector-java-5.1.38-bin.jar to my build path, in a folder called "lib" in the project folder, as suggested by Google results. Here's my code:
private void getDBEntries() throws SQLException, ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver"); //Search results suggested adding this line
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "[password]");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from phones_table");
while(rs.next()) {
myList.add(rs.getString(1));
}
rs.close();
st.close();
con.close();
}
This is giving me a ClassNotFoundException on the Class.forName line. If I remove that line, I get the "no suitable driver found" SQLException on the following line.
I've already tried every common solution suggested to other people with similar problems, but no luck. Maybe there's something simple I'm not understanding.
Edit: I do know how to import jars, but I didn't realise that the mysql.jar had to be in the Java lib folder and referenced externally in Eclipse. However, after doing that I still have the same issue.