hi,
I got exception"NoClassDefFoundException" at the runtime of this java code.My DSN connection is correct,sql server is also properly work,when my project excuted on tomcat.but my beans are not executed properly inly becoz of this connection error.plz give the solution to overcome this problem.

In my project i create connection in one package and all related beans in other package.

package conn;//package
import java.sql.*;
public class ConnectionDB
{
	Connection con = null;

	public Connection getConnectionDB()
	{
		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			 con = DriverManager.getConnection("jdbc:odbc:hrm","sa","pass");


		}
		catch (Exception e) { e.printStackTrace(); }
		return con;
	}
public static void main(String args[])
	{
	Connection cc=null;
		ConnectionDB c = new ConnectionDB();
		 cc = c.getConnectionDB();
		if (cc != null)
			System.out.println("connected");
		else
			System.out.println("not connected");
	}

}

Recommended Answers

All 5 Replies

>I got exception"NoClassDefFoundException"

Show us exception trace.

java launcher unable to find that class.

compile it
>javac ConnectionDB.java -d .

run it
>java conn.ConnectionDB

>I got exception"NoClassDefFoundException"

Show us exception trace.

java launcher unable to find that class.

compile it
>javac ConnectionDB.java -d .

run it
>java conn.ConnectionDB

I had already done this.

I had already done this.

"this is the traced error"
Error: Could not find main class conn.ConnectionDB
Exception in thread "main" java.lang.NoClassDefFoundError: conn.ConnectionDB
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: conn.ConnectionDB
at java.net.URLClassLoader$1.run(Unknown Source)
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)
... 1 more

Please verify following steps:
1. Make sure that ConnectionDB.class file must be inside the conn folder.
Eg.

/home/conn/
ConnectionDB.class

2. Make sure that java launcher must be invoke from the parent folder of conn.

/home
java conn.ConnectionDB

Please verify following steps:
1. Make sure that ConnectionDB.class file must be inside the conn folder.
Eg.

/home/conn/
ConnectionDB.class

2. Make sure that java launcher must be invoke from the parent folder of conn.

/home
java conn.ConnectionDB

yes,I already followed these two steps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.