DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2008
    Posts
    1

    Jdbc Connection using MySql DataBase

    I had written the program JDBCConnection. i.e.,
    Code:
     import java.sql.*;
    
       public class Connect
       {
           public static void main (String[] args)
           {
               Connection conn = null;
    
               try
               {
    	       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");
               }
           }
       }
    Here admin is mysql password.

    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.
    i.e.,

    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 06:51 AM. Reason: Added Code Tags

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,652
    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

  3. #3
    Join Date
    May 2007
    Posts
    4

    check class path for executable

    rajeshlab,

    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

Similar Threads

  1. Create Database Connection in the C#.net
    By ani.since1982 in forum .NET
    Replies: 2
    Last Post: 02-08-2008, 12:21 PM
  2. connecting mysql from eclipse
    By elix in forum Java
    Replies: 3
    Last Post: 10-01-2006, 11:15 PM
  3. Replies: 0
    Last Post: 12-11-2001, 12:01 PM
  4. Ado Connection
    By Sok Y. Kim in forum VB Classic
    Replies: 4
    Last Post: 10-29-2000, 11:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links