compilation error using eclipse.....

Hi, I am building a JSP application using the eclipse IDE. I have the code for the db connection file but every time I run this code  I get an error. The error is as follows:

java.lang.NoClassDefFoundError: DBConnect
Exception in thread "main"
BUT, when I compile this file using the CLI from the DOS screen the file gets compiled without a problem.

Can someone tell me how I can compile this file using the eclipse IDE? Thank you.

A
package classes.DBConnection;
import java.sql.*;
public class DBConnect
	{
		public  Connection con = null;
		
		public  Connection Connect()
		   {
				
				Statement stmt = null;
 
				try 
					{
						String driverName = "org.gjt.mm.mysql.Driver";
						Class.forName(driverName);
						
					}
				 catch(Exception e) 
					{
						System.out.println(" Driver Can Not Load . . . " + e);
 
					}
				try
					{
						String serverName = "localhost";
						String mydatabase = "employee";					
						String username = "root";
						String password = "employer"; 
				
 
						String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
					con = DriverManager.getConnection(url, username, password);
					} 
 
				catch (Exception e) 
						{ 
							System.out.println(" Driver Connection Failed . . .  " + e);
						} 
				return con;
			}
 
			
				public  void Disconnect()
						{
							
							try
								{
									if(con != null)
										{
											con.close();
				 						}
								}
							catch(SQLException s)
								{}
							}
				
	}

Open in new window

aej1973Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ajay-SinghCommented:
Whats value of CLASSPATH variable on the classpath?
 
You need to set the same as build path for eclipse project?
0
Peter KwanAnalyst ProgrammerCommented:
Also, you need to include the following line at the beginning of the class where you are calling the DBConnect class:

import classes.DBConnection.*;
0
aej1973Author Commented:
pkwan, I am not yet calling the DBConnect.class, the file I am trting to compile is the DBConnect.class file.
A
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Peter KwanAnalyst ProgrammerCommented:
Did you use the same JDK in the eclipse as you are using in CLI?

You can check it by right clicking your Web Project (as I guess), and then "Properties" -> "Java Build Path". You should see the JDK runtime library version there.
0
Tanya_MikhnoCommented:
I think the problem is that Eclipse can not find the compiled classes

select your package in Package Explorer, right-click and select Properties (the last there).
click on Java Build Path
There is a "Default output folder" textbox there, in the bottom . select Browse there to point it to your compiled classes folder, like
MyProject/WEB-INF/classes

good luck!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aej1973Author Commented:
Thanks Tanya, I will try this and get back to you.
A
0
aej1973Author Commented:
thx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.