Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

installing connector/j

  Asked By: Elliott    Date: May 23    Category: Java    Views: 711
  

i'm trying to learn mysql so i'm new to connector/j driver.i'm using
jdk1.3.1_01 and mysql 3.23.58. i installed connector/j 3.0.9-stable
but when i created this testconnj.java to test the connector/j
installation:

public class testconnj {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Good to go");
} catch (Exception E) {
System.out.println("JDBC Driver Error");
}
}
}

i got :JDBC Driver Error printed out. Can somebody please tell me
the exact steps of installing connector/j or maybe is it something to
do with the software versions i used?

Share: 

 

8 Answers Found

 
Answer #1    Answered By: Indie Williams     Answered On: May 23

yep.

remove the .newInstance().

Next time do a E.printStackTrace(); and include this in your next email.
This makes helping you a lot easier.

 
Answer #2    Answered By: Kuhlbert Schmidt     Answered On: May 23


This is what i got from the stack trace:
C:\jdk1.3.1_01\bin>javac testconnj.java

C:\jdk1.3.1_01\bin>java testconnj
JDBC Driver Error
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass
(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal
(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at testconnj.main(testconnj.java:4)

 
Answer #3    Answered By: Maria Hughes     Answered On: May 23

The jar file containg the com.mysql.jdbc.Driver class  is not inthe class
path.

There are 2 ways you can add them.

Option 1: Use the -cp with the java  command

eg:
C:\jdk1.3.1_01\bin>javac -cp <path_to_jar_file> testconnj.java

Option 2 : Place the Jar file in C:\jdk1.3.1_01\jre\lib\ext directory.

These types of errors are thrown when the Default classloaders of your
class is not able to load the class into the JVM.

 
Answer #4    Answered By: Damian Jones     Answered On: May 23

This
C:\jdk1.3.1_01\bin>javac -cp <path_to_jar_file> testconnj.java

should read as

C:\jdk1.3.1_01\bin>java -cp <path_to_jar_file> testconnj

 
Answer #5    Answered By: Eamon Jones     Answered On: May 23

the jar file mysql-connector-java-3.0.9-stable-bin.jar i had put in
C:\jdk1.3.1_01\jre\lib\ext immediately after dowloading the driver.
When i tried also to include set CLASSPATH=c:\jdk1.3.1_01\jre\lib\ext
into my autoexec.bat (windows 98) i just got this:
C:\jdk1.3.1_01\bin>javac testconnj.java

C:\jdk1.3.1_01\bin>java testconnj
Exception in thread "main" java.lang.NoClassDefFoundError: testconnj

Then i took this off from autoexec.bat again and just left the jar
file in the jdk1.3.1_01\jre\lib\ext directory and got the previous
error shown in my previous posted message

 
Answer #6    Answered By: Rachael Ferguson     Answered On: May 23

All it had to do was with the Winzip software  - I installed  winzip
again , unzipped the connector/j zip file again and overwritten mysql-
connector-java-3.0.9-stable-bin.jar to C:\jdk1.3.1_01\jre\lib\ext.
All is fine now.

 
Answer #7    Answered By: Muhammad Evans     Answered On: May 23

You are not insane. I get almost identical
behavior on WinXP. Never totally solved it
because my objective was to get MySQL JDBC
connectivity in JBuilder and I finally got
that to work. (Next is Tomcat, but I'll
try that bridge again later.) One thing I
found out is that everything had to go into
the classpath, including the location of the
test class  (your testconnj and my connect)
and half of jre/lib/ext. Shouldn't have to
be that way. Got a classpath in my JBuilder
test project something like 1000 characters
long. Partly just venting here. Try adding
the other stuff to your classpath and see if
it helps.

 
Answer #8    Answered By: Kian Evans     Answered On: May 23

Try this:

c:\> set
CLASSPATH=%CLASSPATH%;<path_to_jar_file>\mysql-connector-java-3.0.9-stable-bir.j\
ar;.
c:\> java  testconnj

or this:

java -cp <path_to_jar_file>\mysql-connector-java-3.0.9-stable-bir.jar;.

 
Didn't find what you were looking for? Find more on installing connector/j Or get search suggestion and latest updates.




Tagged: