473,499 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in connecting mysql with java-Reply Needed Urgently

87 New Member
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,

Exception in thread "main" java.lang.NoClassDefFoundError: MysqlConnect

Coding Part:

import java.sql.*;
import java.lang.*;

public class MysqlConnect{
public static void main(String[] args)throws SQLException {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "customer";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
Class.forName(driver);
conn = DriverManager.getConnection(url+dbName,userName,pa ssword);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (java.lang.ClassNotFoundException e) {
//System.out.println("Could not connect");
e.printStackTrace();
}
}
}


Execution steps:

C:\PROGRA~1\Java\jdk1.6.0_01\bin>javac -classpath "c:\program files\java\jdk1.6.
0_01\jre\lib\ext\mysql-connector-5.0.7-bin.jar" MysqlConnect.java

C:\PROGRA~1\Java\jdk1.6.0_01\bin>java -classpath "c:\program files\java\jdk1.6.0
_01\jre\lib\ext\mysql-connector-5.0.7-bin.jar" MysqlConnect

Result which i get is:

Exception in thread "main" java.lang.NoClassDefFoundError: MysqlConnect

I have specified the classpath clearly and i have the jar file of mysql driver in the location,

"c:\program files\java\jdk1.6.0_01\jre\lib\ext\mysql-connector-5.0.7-bin.jar"

But still i get the same result as specified in execution part above.

I am too tired in finding out the solution.....

Urgent...Please help me to connect to mysql server.
Sep 30 '07 #1
5 2714
JosAH
11,448 Recognized Expert MVP
Never put anything in that lib\ext directory of your jdk. Preferably don't put anything
in any of the two ext directories; neither in the jdk nor jre locations. Put your jar
anywhere you like and make your classpath value point at that jar.

kind regards,

Jos
Sep 30 '07 #2
Ananthu
87 New Member
Hi

I have placed the mysql driver file(jar file) outside the jdk folder. But the same error occurs when i try to execute my java program. Please guide me in connection of mysql with java.
Sep 30 '07 #3
JosAH
11,448 Recognized Expert MVP
Hi

I have placed the mysql driver file(jar file) outside the jdk folder. But the same error occurs when i try to execute my java program. Please guide me in connection of mysql with java.
Good; look at the error message: it can't find your own class; better append the
following to your classpath variable: ;. (that reads semicolon dot) which tells
the jvm that it should look in the current working directory for classes too. The
current working directory is where you stord your .class file.

kind regards,

Jos

ps. please stop opening new threads on the same subject; I'll delete them.
Sep 30 '07 #4
Ananthu
87 New Member
Hi

Atlast with your guidance i have connected mysql with java.Thaks for your kind help and guidance. Sorry for posting the same thread again and again. Here after i will not do this. Thank you so much.

Please keep in touch with me in this kind of troubleshooting activity as and when i require.
Sep 30 '07 #5
JosAH
11,448 Recognized Expert MVP
Hi

Atlast with your guidance i have connected mysql with java.Thaks for your kind help and guidance. Sorry for posting the same thread again and again. Here after i will not do this. Thank you so much.

Please keep in touch with me in this kind of troubleshooting activity as and when i require.
You're welcome of course; your problem was not about database connections;
it was a classpath problem (which you hopefully don't experience anymore from
now on).

There are plenty of people roaming around here that are very well capable of
answering Java questions. Just ask your question here if you bump into one.

kind regards,

Jos
Sep 30 '07 #6

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

Similar topics

1
2582
by: kaiwing18 | last post by:
Hi , I have a problem relate to java and database. Could anyone answer me ?Please see the following code. import java.sql.*; public class Result { public static void main(String args) {
2
5252
by: Marc Stiegele | last post by:
Hello, I have a problem with the IBM DB2 UDB XML Extender. I`m working on a iSeries 400 server (AS/400, V5R1) with a integrated DB2 (my client is NT 4.0 Service Pack 1 with JDK1.1.8). I want to...
3
2225
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...
0
2847
by: NoaGross | last post by:
Hi, I'm relly new in java and I have a problem. I'm using java applet. When using http all ok, but when trying to use https i get: Java Plug-in 1.5.0_10 Using JRE version 1.5.0_10 Java...
0
1695
by: nrip | last post by:
Dear All, I am facing a very peculiar problem. I am reading a CSV file from my JSP code and trying to insert them into MYSQL database. the program first reads a line and then splits it into words...
8
3827
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...
10
1830
by: sssk28 | last post by:
i have installed fedora core 6 and i am getting following error: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this...
1
2129
by: sethupnr | last post by:
when i'm using a simple JSP-mysql code it shows some HTTP status 500 error.But simple JSP program without databse is running , Please help how to solve this problem. I'm new to JSP. my...
1
4318
by: spatro | last post by:
Hi, I am trying to install DBD::mysql using the CPAN and I am facing the following error: cpan> install DBD::mysql CPAN: Storable loaded ok Going to read /root/.cpan/Metadata Warning:...
1
2261
by: whitep8 | last post by:
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 :-)
0
7128
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
7006
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
7215
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
7385
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...
0
5467
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,...
0
3096
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...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1425
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 ...
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.