problem with jdbc driver while running "myapplication".jar

Hi there guys,

I have a problem running my java appplication from an exported .jar file. In fact, when i'm running my prog on bluej(Java IDE) it runs correctly with no probs or exceptions. But when it comes to export my application into a .jar file, i get the exception"No suitable driver found jdbc:mysql://localhost:3306/mydb"

....

I,ve tried changing the windows classpath but nothing.....

I would appreciate it if you give me a clue bout what's going on my PC...:)

Thanx in advance!

[540 byte] By [Epistimosa] at [2007-11-27 11:55:12]
# 1

> Hi there guys,

>

> I have a problem running my java appplication from an

> exported .jar file. In fact, when i'm running my prog

> on bluej(Java IDE) it runs correctly with no probs or

> exceptions. But when it comes to export my

> application into a .jar file, i get the exception

> "No suitable driver found

> jdbc:mysql://localhost:3306/mydb"

> ....

> I,ve tried changing the windows classpath but nothing.....

If you mean a CLASSPATH environment variable, that won't help. It does nothing for you. It's ignored by IDEs, app servers, etc. Delete it.

Use the -classpath option on java.exe to add the JDBC JAR to your runtime CLASSPATH.

%

duffymoa at 2007-7-29 19:00:35 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

you mean

java -classpath 'C:\...\java\jdk1.6.0\jre\bin\ext\mysql-connector-java.jar' ? cauz when i type that i receive an error java.lang.NoClassDefFoundError....

Epistimosa at 2007-7-29 19:00:35 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

> you mean

>

> java -classpath

> 'C:\...\java\jdk1.6.0\jre\bin\ext\mysql-connector-java

> .jar' ? cauz when i type that i receive an

> error java.lang.NoClassDefFoundError....

Then you didn't do it right.

That is not where you should be putting 3rd party JARs. Create a /lib directory closer to your .java files and copy the MySQL JAR into it.

%

duffymoa at 2007-7-29 19:00:35 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

You DID include the name of the .class file with the main method, right?

Should be java -classpath .;<names of 3rd party JARs> YourClassWithMain

Note the "dot" at the start of the CLASSPATH. It says the current directory is also included in the places with the JVM should look for .class definitions.

%

duffymoa at 2007-7-29 19:00:35 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

ok i got it....hope it works....But the question remains....Why does it work correctly

with my IDE environment and not in a .jar file(without having to make any changes at all)?

Anyways, enough is enough thank you very much for your interest and for\

sharing your experience with me...i really appreciate it!

C ya around :0)

Epistimosa at 2007-7-29 19:00:35 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

> ok i got it....hope it works....

Why "hope"? You don't know? You didn't try it?

> But the question

> remains....Why does it work correctly

> with my IDE environment and not in a .jar

> file(without having to make any changes at all)?

I have no idea what you're doing. The IDE apparently is smarter about CLASSPATH than you are.

> Anyways, enough is enough thank you very much for

> your interest and for\

> sharing your experience with me...i really appreciate

> it!

>

> C ya around :0)

You're welcome.

%

duffymoa at 2007-7-29 19:00:35 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7

BlueJ is an IDE tailored for helping newbies get started. I think it's made it possible for you to write some simple things, but it has kept you from really understanding how CLASSPATH works.

%

duffymoa at 2007-7-29 19:00:35 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...