Re: Logging in to MySQL
23.10.2009 12:47, Roedy Green kirjoitti:
I seems to me I was able to login to a MySQL database some years ago,
but now for the life of me I can't get the simplest code to work.
Here is my SSCCE. I can access the database fine from the command
line with mysql -uroot -psesame
You forgot to load the driver.
public class DBDemo
// The JDBC Connector Class.
private static final String dbClassName = "com.mysql.jdbc.Driver";
// Connection string. emotherearth is the database the program
// is connecting to. You can include user and password after this
// by adding (say) ?user=paulr&password=paulr. Not recommended!
private static final String CONNECTION =
public static void main(String args) throws
// Class.forName(xxx) loads the jdbc classes and
// creates a drivermanager class factory
// Properties for user and password
Properties p = new Properties();
// Now try to connect
Connection c = DriverManager.getConnection(CONNECTION,p);
System.out.println("It works !");
You're at the end of the road again.