0

I just created a Class Jdbc when i tried to run an error is shown.

Exception in thread "main" java.lang.NoClassDefFoundError: Jdbc

Here's the code

import java.sql.*;
public class Jdbc {
    public static void main(String [] args)
    {
        try{
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ims","","");
        Statement st=con.createStatement();
        DatabaseMetaData meta=con.getMetaData();
        ResultSet r=meta.getTables(null,null,"%",null);
        String tableNames="";
        while(r.next()){
        tableNames=r.getString(3);
        System.out.println(tableNames);
        }
        }catch (Exception e){}}}

4 Answers4

0

Its most likely that your program is not able to find the class
Place the mysql jdbc driver mysql-connector-java-5.x.x.jar in classpath and then check.

0

The 2 quick fixes would be either

1) Pass the classspath to the execution java -classpath mysql.jar

See

JAVA classpath pass file as command line argument

2) Put the mysql jar in your JRE's extdirectory. Details.

You probably want to put your class in a package since you're using the default package. Also an IDE such as Eclipse could help you for convienience. You don't tell us your execution environment or build path and your result may depend on if you're running the program from the command line, from a runnable jar or from an IDE.

I use the Eclipse Juno IDE so I don't need to worry about setting my classpath. For Ubuntu and MS-Windows, Eclipse IDE is a development environment you might want to use.

Community
  • 1
  • 1
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
0

The issue is not with mysql jar but your own class "Jdbc" is not on classpath, add it to classpath.

If you are running from console add .; to classpath.

Abdullah Shaikh
  • 2,567
  • 6
  • 30
  • 43
0

!. Make sure that the jar is in your class path
2. If not then download it from here

Foredoomed
  • 2,219
  • 2
  • 21
  • 39
  • i got the solution i just add class file path in my class path nor problem with connector thanks every one –  Mar 25 '13 at 07:19