473,387 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

connecting to mysql, with java, on a mac

65
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.  
Oct 26 '09 #1
1 2258
Dököll
2,364 Expert 2GB
You do not need the third slash: jdbc:mysql:///test
Nov 9 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Brendan | last post by:
Unable to connect to any hosts due to exception: java.security.AccessControlException: access denied (java.net.SocketPermission localhost resolve) CAN ANYONE HELP?? What is causing this...
3
by: Jeremy Dillinger | last post by:
I am trying to design a program that will use data from a MySQL database. Currently all the data is being used with PHP scripts from a website. I am also trying to build a software solution that...
7
by: Frances | last post by:
this seems pretty straight-forward.. got this code $link = mysql_connect('localhost:3306', '<uid>', '<pswd>'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected...
11
by: menmysql | last post by:
i am getting the following error while connecting mysql database using jsp java.sql.SQLException: Communication link failure: Bad handshake can any one tell what is the actual problem
8
by: mouac01 | last post by:
I'm not sure if this is possible. I would like to have a PHP app on the Internet connect and write to a local database (Intranet). For example, users would go to a web site...
1
by: peggitt | last post by:
I need help. I need code to connect my java program with a mysql database hosted by an internet service provider(domain). The java program should run locally but read and write to a database on the...
5
by: Ananthu | last post by:
Hi I have done all the codings part for connecting mysql server with java application but when i try to compile,the compilation is successful and during execution i get the following message, ...
8
by: Ananthu | last post by:
Hi I have done all the codings part for connecting mysql with java in eclipse environment. Coding Part: import java.sql.Connection; import java.sql.DriverManager; public class...
2
by: rathnaravi | last post by:
I am using NetBeans 5.0.I tried to connect MySQL with Crystal Reports XI.When writing the coding in Java Application.I get the following error....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.