473,396 Members | 1,712 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,396 software developers and data experts.

How to make a successful connection to MySQL Database

Hi

Can someone please take me through how to make a connection to a MySQL database using Java in Netbeans.

I have downloaded the driver from MySQL, unzipped it to my location, and added the driver to the editor. After adding the driver, I can see it in the editor and my database along with the tables.

However, when I use Java code to make a connection, I get the following exception message:

Exception:com.mysql.jdbc.Driver

My code is below, it is very simple and basic. However, I would welcome guidance on how to make a proper class where I can call it from the main rather than being place in the main.
Expand|Select|Wrap|Line Numbers
  1. import java.sql.* // -- this is placed right at the top!
  2.  
  3.  
  4.   Connection con = null;
  5.  
  6.         try
  7.         {
  8.             Class.forName("com.mysql.jdbc.Driver").newInstance();
  9.             con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bank","root","triumph");
  10.  
  11.             if(!con.isClosed())
  12.                 System.out.println("Successfully Connected");
  13.  
  14.         }catch(Exception e){
  15.             System.err.println("Exception:" + e.getMessage());
  16.         }
  17.     }
  18.  
Can anyone help me?
Nov 12 '08 #1
1 3617
Nepomuk
3,112 Expert 2GB
Hi NewJavaProgrammer! Welcome to bytes.com!
...However, when I use Java code to make a connection, I get the following exception message:

Exception:com.mysql.jdbc.Driver
I'm sure, that isn't the complete error you get, is it? There should be more information.

Also, please use the [CODE]...[/code] tags when posting code - I've added them for you this time.

Oh, and if you haven't done so already, please read our Posting Guidelines.

Greetings,
Nepomuk (Moderator)
Nov 12 '08 #2

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

Similar topics

1
by: Titus Cheung | last post by:
Hello, Thought I read somewhere saying that there is a limit to how many connections are available per mySQL account or something like that. Can someone please clarify? I wrote a PHP tool...
6
by: Jaime Andres Aranguren Cardona | last post by:
Hi, I created mysql table with one index column, with AUTO_INCREMENT feature. (and the other columns too: Nombre, Apellidos, email, Direccion, Ciudad, Pais) In my code, I have: // Take dat...
0
by: Gregory | last post by:
I am using OS X and Dreamweaver MX. I am trying to make a connection to the MySQL Server from within Dreamweaver using the Applications panel and clicking on the "+". A window opens asking for:...
4
by: chris | last post by:
I open MySQL Manager and connect to my database. I then insert one record in to an InnoDB table in MySQL (4.0 and 4.1 alpha hosted on XP running mysqld --console). I then retrieve the record...
0
by: Rajesh Kapur | last post by:
Hello, When I connect to the MySQL server (4.0.16 on Linux) using mysql and let the tool sit for a couple of minutes, I get the following error. mysql> use mysql; No connection. Trying to...
6
by: Ian Davies | last post by:
Hello I have the following code to connect to mySQL database from VB6 ******************************************** Private Sub Form_Load() Dim conn As ADODB.Connection Set conn = New...
10
by: Extremest | last post by:
I know there are ways to make this a lot faster. Any newsreader does this in seconds. I don't know how they do it and I am very new to c#. If anyone knows a faster way please let me know. All...
1
by: Subangini | last post by:
"Hi, I am trying to migration Oracle database to mysql database using visual coding. I am having problem in the Do until loop, can u tell me what is the mistake. Oracle Database - Oracle...
7
by: BillCo | last post by:
I need to Connect to an online mySQL database from Access using JET ODBC with no saved DSN. Anyone out there who as made this work and can give example of how it's done? I've seen lots of posts...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.