|
-
March 10th, 2002, 07:50 PM
#1
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 = "jdbc dbc.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();
}
}
}
}
-
March 11th, 2002, 05:42 AM
#2
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.
-
June 22nd, 2005, 08:54 AM
#3
Re: Help!!! Connecting to a DB
 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.
-
June 27th, 2005, 01:24 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|