wood burning stoves 2.0*
The moose likes JDBC and the fly likes problem with mysql connecton! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem with mysql connecton!" Watch "problem with mysql connecton!" New topic
Author

problem with mysql connecton!

Himal Chuli
Ranch Hand

Joined: Aug 06, 2002
Posts: 118
hi folks,
i downloaded mm.mysql-2.0.14-you-must-unjar-me and put it in CLASSPATH. trying to make a connection to mysql from a servlet. when i execute servlet, gives me the following error;
java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver .could you please give me a hints where did i go wrong?
thanks.


Himal
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I'd suspect that your classpath isn't set correctly. Take a look at the instructions at the top of the JDBC assignments in The JavaRanch Cattle Drive.
[ April 09, 2003: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Also, if I recall correctly, you have to unjar the file with the words "unjar-me" as part of the name and it's the "mm.mysql-2.0.14-bin.jar" file that should be in your classpath.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

FYI - mm.mysql is pretty old. It was maintained by Mark Mathews who was then hired by the MySQL Team of developers to continue production on the Driver which is now called Connector/J. Not that this will solve your problem, but you will get more functionallity out of the newer driver. Information and Download can be found here


GenRocket - Experts at Building Test Data
Himal Chuli
Ranch Hand

Joined: Aug 06, 2002
Posts: 118
thanks guys for your prompt help but i still don't seem to get it working. As Dirk mention, i unjar and put it into CLASSPATH, still it does not find the org.gjt.mm.mysql.Driver. i even tried using Connector/j as Gregg mentioned, still the problem is same. i am tired but i need to get it working. wonder if i am doing something wrong here. i don't know why it does not work. please give me help here.
thanks.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
You mentioned that this is a problem when "executing" a servlet. So, this must be a runtime problem.
The JAR file needs to be "locateable" by your Servlet container. So, you probably want to add the JAR file to the lib folder of your web application. Or, for example, with a default installation of Tomcat, you could add it to the common/lib folder and then it would be accessible to any web app running on Tomcat.
The Cattle Drive explains doing this same thing with Orion Server.
Any luck?
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I downloaded the Development version of the MySQL. Nonetheless, it should work for you.
1. download the Connector/J (mysql-connector-java-3.1.0-alpha.zip).
Unzip the outer file into your root directory (C:\).
2. at the very beginning, type:
C:\> C:\mysql\bin\mysqld-nt --standalone
to start mysql server
3. and when you make changes you should compile java files again

4. Using the JDBC Driver
In order to use the JDBC driver, you just need
to put it on your classpath, OR installing it
as a Java extension library.
4.1. to put it on the classpath:
WINDOWS:
set classpath=.;C:\mysql-connector-java-3.1.0-alpha\mysql-connector-java-3.1.0-alpha-bin.jar;%classpath%
(of course, you'll need to change the folders to the folder you put the JAR into)
4.2. if you put it in your jre/lib/ext folder of your JDK/JRE, the JDBC Driver will also be found automatically.

4.3. alternatively, run the program this way:
java -classpath C:\mysql-connector-java-3.1.0-alpha\mysql-connector-java-3.1.0-alpha-bin.jar; TestServlet localhost test
where TestServlet is the name of the Java program and test is the name of the database.
4.3. The driver is mysql-connector-java-3.1.0-alpha-bin.jar, placed it in
C:\jakarta-tomcat-4.1.18-LE-jdk14\common\lib directory
5. prepare the web.xml file for running Servlets
6. Compile the test program:

javac -d C:\jakarta-tomcat-4.1.18-LE-jdk14/webapps/ROOT/WEB-INF/classes TestServlet.java
7. Run it by the following command:

start the Tomcat and
http://localhost:8080/servlet/TestServlet

Here is the code for the TestServlet.java

[ April 09, 2003: Message edited by: JiaPei Jen ]
[ April 09, 2003: Message edited by: JiaPei Jen ]
[ April 09, 2003: Message edited by: JiaPei Jen ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Those look like decent step-by-step instructions. Thanks JiaPei Jen.
I would suggest using a stable version of ConnectorJ, instead of that scary alpha stuff.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with mysql connecton!