i have the problem of the connection java to MySQL
i oledi download the entire software:
-J2SE development kit 5.0 update6.0
-MySQL connector/j 3.1.12
is it enough for me to connect the java application to MySQL??
i oledi set the classpath like that:
my computer right click>properties >advanced >Environment Variables> System Variables>
create CLASSPATH and key in my .jar url which is:
is it i inthe right path?
when i compile the source code, the error line come out:
Test.java:20: unreported exception java.lang.ClassNotFoundException; must be cau
ght or declared to be thrown
And my source code is:::
public class Test
static final String JDBC_DRIVER = "org.gjt.mm.mysql.driver";
static final String DATABASE_URL = "jdbc:mysql://localhost/test";
The line of code which urmaniac pointed out is your problem.
Check out the javadocs for Class.forName(). It returns a reference to the class passed in. Your usage of it does not assign it to anything and doesn't really do much. Also, you failed to catch any of the exceptions it throws. You need to add more catch statements before your finally clause or get rid of that line of code.