473,545 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make a successful connection to MySQL Database

1 New Member
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.m ysql.jdbc.Drive r

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 3625
Nepomuk
3,112 Recognized Expert Specialist
Hi NewJavaProgramm er! Welcome to bytes.com!
...However, when I use Java code to make a connection, I get the following exception message:

Exception:com.m ysql.jdbc.Drive r
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
8942
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 that uses a different PHP file whenever someone hit an HTML form button (ie Submit). It turned out that each one of these PHP files need to re-open...
6
2145
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 from HTML form $Nombre = $_POST;
0
2254
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: Connection Name: Apress MySQL Server: localhost User Name: apress Password: xxxxxx Database (Select): When I click select so the Dreamweaver...
4
2260
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 successfully in MySQL Manager using the existing connection. This indicates that commit is running successfully, (I have seen this on the database...
0
1083
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 reconnect... Connection id: 50791 Current database: *** NONE ***
6
676
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 ADODB.Connection conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
10
2162
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 I am doing is quering the db for all the headers for a certain group and then going through them to find all the parts of each post. I only want...
1
2451
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 rdb with VMS operating system Mysql- version 5 Visual basic - version 6.0 Since my host machine Oracle is an older version I have problem, do
7
5557
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 saying it's possible, but no code. This has to be Jet ODBC, because the users are technophobes and I wouldnt expect them to download and install a...
0
7478
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7410
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7923
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7437
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5984
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4960
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3466
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
722
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.