[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 575
  • Last Modified:

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

0
aej1973
Asked:
aej1973
1 Solution
 
Ajay-SinghCommented:
Whats value of CLASSPATH variable on the classpath?
 
You need to set the same as build path for eclipse project?
0
 
Peter KwanCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Peter KwanCommented:
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
 
aej1973Author Commented:
Thanks Tanya, I will try this and get back to you.
A
0
 
aej1973Author Commented:
thx
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now