No Suitable Driver in Eclipse but not TextPad [message #493334] |
Sat, 24 October 2009 19:19  |
Eclipse User |
|
|
|
I'm getting a No Suitable Driver Found error when I run my program in Eclipse. It runs fine when I run it through TextPad so I'm not sure what is causing it. Must be related to Eclipse but I'm new to Eclipse so I'm not sure how to resolve the issue.
public Connection getConnection(String url) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
{
System.setProperty("jdbc.drivers", "sun.jdbc.odbc.JdbcOdbcDriver");
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch (ClassNotFoundException e)
{
System.out.println("Class Not Found");
//System.exit(1);
}
catch (InstantiationException e)
{
System.out.println("Instantiation failed");
}
catch (IllegalAccessException e)
{
System.out.println("Illegal Access");
}
return DriverManager.getConnection(url);
}
|
|
|
|
|
|
|
|
|
Re: No Suitable Driver in Eclipse but not TextPad [message #493537 is a reply to message #493408] |
Mon, 26 October 2009 12:58   |
Eclipse User |
|
|
|
Geoff wrote:
> Walter Harley wrote on Sun, 25 October 2009 14:24
>> As Remy says, almost certainly a classpath problem. Take a look at
>> how the classpath is being set in the Eclipse launch configuration for
>> your application (on the Run As... dialog).
>
>
> OK good, this is what I was looking for. Is there something I should be
> "running as" in order to enable the driver to initiate? I'm sorry to
> sound dependent but I'm new to Eclipse, I love the features and would
> like to be able to use it for this application. I tried running as Java
> Application but still got the same thing. I looked in the help file but
> couldn't really find anything specific to what I'm looking for.
>
> Here is my classpath contents:
> ;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\Program
> Files\Java\mysql-connector-java-5.1.10\mysql-connector-java- 5.1.10-bin.jar
>
What Dave said is apropos. And more broadly, you might want to spend a bit of
time with some of the Eclipse tutorials, just to get a bit more of a leg up on
how to configure and work with Eclipse.
To elaborate a little on one of Dave's points: there are three different
classpaths to be aware of when you are running Eclipse. First, Eclipse itself
is a Java application, so it has a classpath; mostly you don't care about this
one, except to make sure you're not confusing it with the others. Second, there
is the classpath (referred to as the Java Build Path) that is in effect when you
compile your code. This affects what classes are visible - for instance, if
your code contains a reference to a class named Foo, then there must be a
project or a jar file containing Foo on your project's build path. Third, there
is the classpath that is in effect when you run your application; this may
contain additional or different jars than the build path, because (for instance)
your app might compile against an interface (IFoo) but reflectively load an
implementation class (Foo) at runtime.
Often the runtime classpath is the same as the build path, but ultimately it's
controlled by the launch configuration. Sometimes the app itself (or code in
jars it references) may extend the classpath by loading libraries from specific
URLs or disk locations; that's why I've been emphasizing the need to make sure
where your app is running from, in case it is internally trying to dynamically
load a library with a relative pathname.
You probably want to Run As... Java Application. Once you've done this once,
there will be a launch configuration; if you go to the dialog, you'll notice
there are a bunch of tabs. I'd suggest paying attention to the contents of each
of those tabs; in particular, the field that lets you set the directory that the
application will be launched in.
|
|
|
|
Powered by
FUDForum. Page generated in 0.12573 seconds