473,546 Members | 2,196 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.NoCla ssDefFoundError : MysqlConnect

Coding Part:

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

public class MysqlConnect{
public static void main(String[] args)throws SQLException {
System.out.prin tln("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(d river);
conn = DriverManager.g etConnection(ur l+dbName,userNa me,pa ssword);
System.out.prin tln("Connected to the database");
conn.close();
System.out.prin tln("Disconnect ed from database");
} catch (java.lang.Clas sNotFoundExcept ion e) {
//System.out.prin tln("Could not connect");
e.printStackTra ce();
}
}
}


Execution steps:

C:\PROGRA~1\Jav a\jdk1.6.0_01\b in>javac -classpath "c:\program files\java\jdk1 .6.
0_01\jre\lib\ex t\mysql-connector-5.0.7-bin.jar" MysqlConnect.ja va

C:\PROGRA~1\Jav a\jdk1.6.0_01\b in>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.NoCla ssDefFoundError : 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 2719
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
2589
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
5262
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 create XML files out of the DB2 data using the XML collections method and SQL mapping. I successfully enabled my database, put the collection.dtd...
3
2230
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 can use the same data. I have gone through all the data connectors in Visual Basic.net and none of them have the options for connecting to MySQL. Does...
0
2851
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 HotSpot(TM) Client VM User home directory = C:\Documents and Settings\noa ---------------------------------------------------- c: clear console window
0
1699
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 using the split function and then inserts them into different fields of the database. But the problem is that the JSP ; token=line.split(" ");...
8
3830
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 http://www.internet.com to run the app. The app requires an internet connection and is outside of the user's network. The app would have the option to either store...
10
1831
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 request. exception
1
2135
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 configurations are... i installed j2sdk in C:\j2sdk1.4.2_16 then installed jakarte-tomcat in C:\Program Files\Apache Tomcat 4.0 folder copied...
1
4323
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: Found only 0 objects in /root/.cpan/Metadata CPAN: LWP::UserAgent loaded ok
1
2267
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
7507
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
7698
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
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
7461
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
6030
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...
1
5361
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3492
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
1922
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
747
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.