Mac leapord. NetBeans. Mysql and class path

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • whitep8
    New Member
    • Oct 2009
    • 65

    Mac leapord. NetBeans. Mysql and class path

    Hi All,

    The code at the bottom of this message is an example (1 of 3 i have tried) of trying to connect to a localhost mysql database.

    It wont, and the exception displayed is the one i have set.

    Im fairly convinced its something to do with the driver not being installed.

    I have downloaded it and unzipped it and installed it, and got the green success tick.

    But it still will not connect.

    How do i set a class path?
    My only other option is to dual boot windows, which i really dont want to do.

    Code:
    import java.sql.*;
    
       public class Connect
       {
           public static void main (String[] args)
           {
               Connection conn = null;
    
               try
               {
                   String userName = "root";
                   String password = "root";
                   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");
               }
               finally
               {
                   if (conn != null)
                   {
                       try
                       {
                           conn.close ();
                           System.out.println ("Database connection terminated");
                       }
                       catch (Exception e) { /* ignore close errors */ }
                   }
               }
           }
       }
  • whitep8
    New Member
    • Oct 2009
    • 65

    #2
    good evening all,

    I finally managed to get this script to work.

    I had to javac it with the driver in the same directory and it worked fine.

    That leads onto my question, how can i avoid that and get it to run in netbeans?

    Comment

    • Dököll
      Recognized Expert Top Contributor
      • Nov 2006
      • 2379

      #3
      Thanks for letting us know that it worked and what you did to arrive at that conclusion, get a load of this link:



      Also, fire Google, type in "Netbeans Video Tutorials for Web Applications" and get yourself some coffee call it a night.

      You should come out happy:-)
      Last edited by Dököll; Nov 10 '09, 01:33 AM. Reason: coffee for coofee:-)

      Comment

      Working...