Skip to main content



      Home
Home » Newcomers » Newcomers » No Suitable Driver in Eclipse but not TextPad
No Suitable Driver in Eclipse but not TextPad [message #493334] Sat, 24 October 2009 19:19 Go to next message
Eclipse UserFriend
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 #493376 is a reply to message #493334] Sun, 25 October 2009 10:02 Go to previous messageGo to next message
Eclipse UserFriend
On Sat, 24 Oct 2009 19:19:06 -0400, Geoff wrote:

> I'm getting a No Suitable Driver Found error when I run my program in
> Eclipse.

What is the full stack trace?

> 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.

It is probably a classpath problem I guess. By the way, can you run your
application from the command line?

Regards,
Remy
Re: No Suitable Driver in Eclipse but not TextPad [message #493387 is a reply to message #493376] Sun, 25 October 2009 12:17 Go to previous messageGo to next message
Eclipse UserFriend
Here is the stack trace
java.sql.SQLException: No suitable driver found for jdbc:mysql://172.20.96.6:3306/dashboard_data
	at java.sql.DriverManager.getConnection(Unknown Source)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at DB_Connection.getConnection(DB_Connection.java:77)
	at DB_Connection.<init>(DB_Connection.java:29)
	at Dashboard_GUI.runMain(Dashboard_GUI.java:317)
	at Dashboard_GUI.main(Dashboard_GUI.java:86)

It runs from the command line as well. So, it works from cmd and from TextPad but not Eclipse.....
Re: No Suitable Driver in Eclipse but not TextPad [message #493394 is a reply to message #493334] Sun, 25 October 2009 14:24 Go to previous messageGo to next message
Eclipse UserFriend
Geoff wrote:
> 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.
>


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).

Also note that the working directory is probably not the same in your various
scenarios. If you, or the driver, have any code that assumes a certain working
directory, you'll need to specify it in the launch config.
Re: No Suitable Driver in Eclipse but not TextPad [message #493408 is a reply to message #493394] Sun, 25 October 2009 21:49 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: No Suitable Driver in Eclipse but not TextPad [message #493519 is a reply to message #493408] Mon, 26 October 2009 11:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

"Geoff" <ribbs2521@gmail.com> wrote in message
news:hc2v6q$kn7$1@build.eclipse.org...
> 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
>
Is this your system classpath or your launch config classpath? My guess is
it is the system classpath. If so, this will not be used when launching
from Eclipse. You most likely need to add the mysql jar to your project and
include it on the launch config classpath. Check out the Help about adding
libraries to a Java project.
Re: No Suitable Driver in Eclipse but not TextPad [message #493535 is a reply to message #493519] Mon, 26 October 2009 12:59 Go to previous messageGo to next message
Eclipse UserFriend
Awesome, I looked up how to add libraries to my project. I added the driver JAR file and now it works beautifully. Thanks a lot for your help everyone.
Re: No Suitable Driver in Eclipse but not TextPad [message #493537 is a reply to message #493408] Mon, 26 October 2009 12:58 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: No Suitable Driver in Eclipse but not TextPad [message #493598 is a reply to message #493535] Tue, 27 October 2009 03:38 Go to previous message
Eclipse UserFriend
Geoff wrote:
> Awesome, I looked up how to add libraries to my project. I added the
> driver JAR file and now it works beautifully. Thanks a lot for your
> help everyone.

Excellent! Glad you got it to work.
Previous Topic:Localized versions of Eclipse
Next Topic:Create and Select workingset automatically
Goto Forum:
  


Current Time: Mon Sep 08 14:13:26 EDT 2025

Powered by FUDForum. Page generated in 0.09394 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top