CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2000
    Posts
    58

    Help!!! Connecting to a DB

    hi,

    I am a beginner at Jbuilder and I am writing a test class which connects to a database. I have written the following code, but I get the error -

    " java.lang.NoClassDefFoundError: junit/textui/TestRunner
    Exception in thread "main" "

    Does anyone know what I may be doing wrong, or what I have to do to get this to work?

    Thanks heaps.

    package prudentia;

    import sun.jdbc.odbc.JdbcOdbcDriver.*;
    import java.sql.*;
    import java.io.*;

    /**
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2002</p>
    * <p>Company: </p>
    * @author unascribed
    * @version 1.0
    */

    public class PrudclsDBConnect {
    static Connection connection;
    static String driver = "COM.cloudscape.core.JDBCDriver";
    String url = "jdbcdbc.north ";
    String user = "";
    String password = "";

    public void initialize() throws SQLException {
    //Class.forName(driver);
    connection = DriverManager.getConnection(url, user, password);
    System.out.println("Hello World");
    }

    public void close() throws SQLException
    {
    try {
    connection.close();
    } catch (SQLException e) {
    throw e;
    }
    }

    public static void main(String[] args)
    {
    PrudclsDBConnect clsDBConnect = new PrudclsDBConnect();
    try {
    clsDBConnect.initialize();
    clsDBConnect.close();
    } catch(SQLException sqlException) {
    while(sqlException != null)
    {
    sqlException.printStackTrace();
    sqlException = sqlException.getNextException();
    }
    }
    }
    }


  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Help!!! Connecting to a DB

    The error is nothing to do with your test class. The clue is in the error message. A NoClassDefFoundError means the compiler can't find a class file it needs, and is usually followed by the name of the class it is looking for, in this case junit/textui/TestRunner.

    I guess this means you are using Junit to test your class, in which case you should have junit.jar on your classpath (e.g. something like set classpath=%classpath%;c:\junit3.7\junit.jar).

    Incidentally, test classes for Junit usually extend junit.framework.TestCase, have methods called testXxxx(), and typically create a dummy database class rather than connect to a real database - see the Junit docs.

    Dave

    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Feb 2003
    Location
    Sunny Glasgow!
    Posts
    258

    Re: Help!!! Connecting to a DB

    Quote Originally Posted by dlorde

    ...

    I guess this means you are using Junit to test your class, in which case you should have junit.jar on your classpath (e.g. something like set classpath=%classpath%;c:\junit3.7\junit.jar).

    ...

    Dave
    When setting the classpath, how do you cope with spaces?
    For example, my install dir is "D:\Program Files\Eclipse\junit"
    I have tried setting ";D:\Program Files\Eclipse\junit" and ";D:\Program%Files\Eclipse\junit" in the classpath (without the "" marks obviously), but nothing seems to work.

  4. #4
    Join Date
    Jun 2005
    Posts
    33

    Thumbs up Re: Help!!! Connecting to a DB

    1. The shortcut to do the above is use the '.'

    set classpath=%classpath%;.;c:\junit3.7\junit.jar;

    where . represents the current working dir

    which may avoid confusion when the folder name has spaces.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured