MySQL with NetBeans problem
hi,
How do I make a connection do mysql database in my local computer. Im all confused with this.
first I did was added the JDBC mysql driver to this location
C:\Program Files\Java\jdk1.5.0_12\jre\lib\ext\mysql-connector-java-5.0.6-bin.jar
then I added this in the Netbeans IDE =>
> in runtime under database -> drivers I added this file. everything was ok.
I even imported & connected some databases to the IDE runtime window. My question is does this have anything to do with code I write in my programs or is this just a browser for MySQL in netbeans.?
Then I created this small java program which I picked from a tutorial example.
--
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JdbcExample2 {
public static void main(String args[]) {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql:///test",
"root", "123");
if(!con.isClosed())
System.out.println("Successfully connected to " +
"MySQL server using TCP/IP...");
} catch(Exception e) {
System.err.println(e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
}
}
}
The compilation was OK. but when I tried to run I get this error,
java.lang.NoClassDefFoundError: JDBC_examples/JdbcExample2
Exception in thread "main"
Java Result: 1
I followed some forum posts in here & even tried adding this driver to class path variable in environmental variables.
I went to project properties then under libraries => I tried adding the jar file (driver) to all the sections listed there.
ex: compile section, run, compile test, run test...
but still that error appears.
what is causing this error.
How can I fix it.
plz im all confused with this. :(
Thank you.

