473,221 Members | 2,075 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,221 software developers and data experts.

Connecting java application in ECLIPSE with mysql-Reply Needed Urgently

87
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 MysqlConnect {

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

But when i run as java application the following are the errors i get,

Result after executing is:

MySQL Connect Example.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at MysqlConnect.main(MysqlConnect.java:15)

What can i do to get the output?

But when this coding is executed seperately in java application wihtout using Eclipse environment i get the output correctly.

Please give me the procedures for connecting mysql with java application in eclipse environment...
Sep 30 '07 #1
8 4691
JosAH
11,448 Expert 8TB
Goto Project>Properties; select Java Build Path from the tree view and select
Libraries from the tabs; press Add External Jar and add your MySQL jar file.

Now that jar is part of your project and the jvm can find classes etc. from that jar.
Behind the scenes Eclipse has adjusted your classpath for you.

kind regards,

Jos
Sep 30 '07 #2
Ananthu
87
Hi

I have followed all your steps in adding jar file in the java build path in eclipse, but i get the first line output,

Mysql Connect Example

in the console window which i have specified in the first line of my coding. But the rest of the codings didn't work.

That is i get the following errors in debug window,

MysqlConnect [Java Application]
MysqlConnect at localhost:2184
Thread [main] (Suspended (exception FileNotFoundException))
FileInputStream.open(String) line: not available [native method]
FileInputStream.<init>(File) line: not available
ZoneInfoFile$1.run() line: not available
AccessController.doPrivileged(PrivilegedExceptionA ction<T>) line: not available [native method]
ZoneInfoFile.readZoneInfoFile(String) line: not available
ZoneInfoFile.createZoneInfo(String) line: not available
ZoneInfoFile.getZoneInfo(String) line: not available
ZoneInfo.getTimeZone(String) line: not available
TimeZone.getTimeZone(String, boolean) line: not available
TimeZone.setDefaultZone() line: not available
TimeZone.getDefaultRef() line: not available
TimeZone.getDefault() line: not available
Util.<clinit>() line: 80
Driver(NonRegisteringDriver).parseURL(String, Properties) line: 667
Driver(NonRegisteringDriver).connect(String, Properties) line: 280
DriverManager.getConnection(String, Properties, ClassLoader) line: not available
DriverManager.getConnection(String, String, String) line: not available
MysqlConnect.main(String[]) line: 17
C:\Program Files\Java\jre1.6.0_01\bin\javaw.exe (Sep 30, 2007 6:45:57 PM)

What can i do?

Please help me...
Sep 30 '07 #3
JosAH
11,448 Expert 8TB
Was there an exception thrown? What did its stack trace say?

kind regards,

Jos
Sep 30 '07 #4
Ananthu
87
Hi

The errors which i have specified occurs in the debug window. When i click the errors one by one they ask me to edit the source path. What is that? I dont no.

But i get the first line output in the console window and after that i get these errors in debug window.

The errors which i have specified are stack trace errors... and exception error is in thread main.

Please help me...
Sep 30 '07 #5
JosAH
11,448 Expert 8TB
Hi

The errors which i have specified occurs in the debug window. When i click the errors one by one they ask me to edit the source path. What is that? I dont no.

But i get the first line output in the console window and after that i get these errors in debug window.

The errors which i have specified are stack trace errors... and exception error is in thread main.

Please help me...
The source path is the location where the source code resides of the classes
you clicked on. Forget it for now. Press that square red button near the console
window so everything stops then. Press that grey 'X' a couple of times so you
can be sure everything's dead then. When you see another red button, press
it again, i.e. kill all running processes.

You should see two buttons near the top right corner: they're your 'perspectives'
as Eclipse calls them. Click the 'Java' perspective. The 'debug' perspective will
disappear.

Then press Ctrl-F11 and tell us what you see in the console window; there won't
be a debug window, i.e. your application is simply running (and probably crashing
on an Exception that was thrown but not handled).

kind regards,

Jos
Sep 30 '07 #6
Ananthu
87
Hi

Atlast i got the output with your kind guidance. But can you please clear me the following doubts that i have in the procedure you gave me,

what is the purpose of doing clicking the red button in console window and double clicking the X button?

Please clear my last doubt which i have specified above and thanks for your cooperation...
Sep 30 '07 #7
JosAH
11,448 Expert 8TB
Hi

Atlast i got the output with your kind guidance. But can you please clear me the following doubts that i have in the procedure you gave me,

what is the purpose of doing clicking the red button in console window and double clicking the X button?

Please clear my last doubt which i have specified above and thanks for your cooperation...
That square red button simply kills the current running process (you can have
more than one process running). The grey 'X' button removes the console
attached to that process.

Does your code work now? What was wrong before? What did you change?

kind regards,

Jos
Sep 30 '07 #8
Ananthu
87
Hi

Sorry for the late reply. My code successfully worked. I followed your guidance only. By clicking the red stop button and grey X button,i killed all the running process and executed by pressing ctrl+F11. It worked for me. Thank you for your kind guidance.

Just for knowing the purpose of clicking the red button and grey X button, i asked you the previous question. Thank you for your reply...

Please keep in touch with me trobleshooting problems like this...
Oct 1 '07 #9

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

Similar topics

10
by: pmdanger | last post by:
Hi, I'm new in java and my customer want an application which works under LINUX and WINDOWS plat forms. So, i though logically in JAVA. As i need to select my development tool, i would like...
0
by: Donovan | last post by:
Hello. I am interested in learning about and using the Eclipse framework and Java -- both of which are new to me. I have prior programming experience with VB.NET and c#.NET; but not Java. As...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
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...
16
by: Amir Michail | last post by:
Hi, It seems to me that measuring productivity in a programming language must take into account available tools and libraries. Eclipse for example provides such an amazing IDE for java that it...
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...
5
by: E2CMonkeyBoy | last post by:
Quick Intro: was thumbing through a book on Programming Windows in C# and was wondering if I shouldnt fork my developement: I've written a program in windows script, and now a more robust version...
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....
5
by: gerardsmink | last post by:
Hello, I have written a java program that can connect with a mysql server. When i run the program in Eclipse it works fine, when i create a jar and run the program outside eclipse the program...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.