Jdbc Connection using MySql DataBase
I had written the program JDBCConnection. i.e.,
Here admin is mysql password.
public class Connect
public static void main (String args)
Connection conn = null;
String userName = "Root";
String password = "admin";
String url = "jdbc:mysql://localhost:3306/test";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url,userName ,password );
System.out.println ("Database connection established");
catch (Exception e)
System.err.println ("Cannot connect to database server");
I had copied the mysql-connector-java-5.0.8-bin.jar file in the location of C:\Program Files\Java\jdk1.5.0\jre\lib folder and set the class path as same path.
When i had compile the program it has compile successfully. But when i was runeed it has displayed an error message.
Exception in thread "main" java.lang.NoClassDefFoundError: Connect
Please tell me what is the mistake any one knows.
Last edited by Hack; 02-26-2008 at 07:51 AM.
Reason: Added Code Tags
Split from this resolved thread into its own thread.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
check class path for executable
your compiler "javac" could see the classpath to the jar file.
make sure your executable "java" can also see it.
"javac" & "java" are two different programs, and they each require parameters.
this is necessary especially in editors & IDEs that attempt to execute and compile. the parameter is required separately because the executable is different.
hope this helps
By ani.since1982 in forum .NET
Last Post: 02-08-2008, 01:21 PM
Last Post: 10-02-2006, 12:15 AM
By Singer Wyatt in forum Java
Last Post: 12-11-2001, 01:01 PM
By Sok Y. Kim in forum VB Classic
Last Post: 10-30-2000, 12:54 AM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center