Connecting Tech Pros Worldwide Forums | Help | Site Map

connecting to mysql, with java, on a mac

Newbie
 
Join Date: Oct 2009
Posts: 31
#1: 4 Weeks Ago
Hi all,

The following code is throwing "Exception: com.mysql.jdbc.Driver"

do i need to drop a driver file somewhere?

im fairly new to java, so be gentle

Help :-)

Expand|Select|Wrap|Line Numbers
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4.  
  5. public class MySql {
  6.  
  7.   public static void main(String args[]) throws Exception
  8.   {
  9.     Connection con = null;
  10.  
  11.     try {
  12.       Class.forName("com.mysql.jdbc.Driver").newInstance();
  13.       con = DriverManager.getConnection("jdbc:mysql:///test",
  14.         "username", "password");
  15.  
  16.       if(!con.isClosed())
  17.         System.out.println("Successfully connected to " +
  18.           "MySQL server using TCP/IP...");
  19.  
  20.     } catch(Exception e) {
  21.       System.err.println("Exception: " + e.getMessage());
  22.     } finally {
  23.       try {
  24.         if(con != null)
  25.           con.close();
  26.       } catch(SQLException e) {}
  27.     }
  28.   }
  29. }
  30.  

Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,268
#2: 3 Weeks Ago

re: connecting to mysql, with java, on a mac


You do not need the third slash: jdbc:mysql:///test
Reply