I'm having trouble using the JDBC Connector. I got it to work in Eclipse but it doesn't seem to work from command line. I re-named the connector "driver.jar" and put it into a /lib directory in the folder of my Main class. I even set the class path to the /lib/driver.jar but that doesn't seem to do the trick. Can someone please advise me on how to setup the JDBC so that I can connect to a MySQL database. This is really frustrating.
Sample Code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Main {
public static void main(String args[]) {
// Database credentials
Connection conn = null;
String url = "jdbc:mysql://localhost/";
String db = "db";
String driver = "com.mysql.jdbc.Driver";
// Connect to database
try {
Class.forName(driver);
System.out.println("HELLO");
conn = DriverManager.getConnection(url+db,"root","");
System.out.println("Success");
} catch(Exception e) {
return;
}
}
}