• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 513
  • Last Modified:

Using the MySQL JDBC driver

Im an using a simple class file as I have attached, I the following printed to my console when I try to call my servlet.
Now here are the steps I have followed so far,
1. Go to www.mysql.com, download the file "mysql-connector-java-5.1.12"
2. I unziped this file, I copied the file "mysql-connector-java-5.1.12-bin" to the path
jre\lib\ext in my jdk directory.

Is there another step I am missing?

INFO: Server startup in 1151 ms
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/project
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at InsertTable.doGet(InsertTable.java:19)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:404)
      at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:136)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
      at java.lang.Thread.run(Unknown Source)

InsertTable.java
0
bhession
Asked:
bhession
  • 4
  • 4
1 Solution
 
anilallewarCommented:
The "/jre/lib/ext" contains jars for Java extension; put your mySQL jar yunder jre/lib
0
 
anilallewarCommented:
One more thing; if you want to use ext, you need to specify a command property when invoking java. That should work in your case.

java.exe -Djava.ext.dirs =C:\Program Files\java\jre6 \lib\ext mypackage.MyClass
0
 
bhessionAuthor Commented:
That didnt seem to work, I moved the jar, still got the same error
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
anilallewarCommented:
If using Tomcat, place the jar file under your <application directory>/WEB-INF/lib.

Things are a little different when you use a web container; since you are running multiple applications under a single JVM but each having its own classloader. The web app specifications state that all user classes(.class files) need to go under <your web app>/WEB-INF/classes while the application specific jar files need to go under <your web app>/WEB-INF/lib
0
 
bhessionAuthor Commented:
That seems to work but with a slight change to my error printed on my console.
Now on setup of my database I chose a username of "admin" and password of "admin" so not sure whats happening there?

INFO: Server startup in 1992 ms
java.sql.SQLException: Access denied for user 'admin'@'localhost' (using password: YES)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3562)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3494)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:920)
      at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4000)
      at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1285)
      at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2186)
      at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:787)
      at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
      at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:357)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at InsertTable.doGet(InsertTable.java:19)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:404)
      at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:136)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
      at java.lang.Thread.run(Unknown Source)
0
 
anilallewarCommented:
How are you connecting to the database; do you create the connection in in your servlet? There is some error with the schema access for the admin user you created?

Can you post the connection statements in your servlet? Typically check whether the schema that you provide in the JDBC URL has access to the admin user.
0
 
saulat78Commented:
Either you are using a wrong password or your admin does not have rights on that schema.. but thats strange !!!!

Saulat
http://www.einfobuzz.com

0
 
bhessionAuthor Commented:
Hi guys,
I figured out there was a missing step I needed to take before I could use my driver. See the link
http://tomcat.apache.org/tomcat-4.1-doc/printer/jndi-datasource-examples-howto.html

If you scroll down till you come to here,
MySQL DBCP Example    0. Introduction    Versions of MySQL and the mm.mysql JDBC driver when have been reported to work:        * MySQL 3.23.47, MySQL 3.23.47 using InnoDB, MySQL 4.0.1alpha        * mm.mysql 2.0.14 (JDBC Driver)    Please let us know if you have tested the new MySQL mm.mysql 3.0 driver.    1. MySQL configuration    Ensure that you follow these instructions as variations can cause problems.    Create a new test user, a new database and a single test table. Your MySQL user must have a password assigned. The driver will fail if you try to connect with an empty password.                              mysql> GRANT ALL PRIVILEGES ON *.* TO javauser@localhost        ->   IDENTIFIED BY 'javadude' WITH GRANT OPTION;    mysql> create database javatest;    mysql> use javatest;    mysql> create table testdata (        ->   id int not null auto_increment primary key,        ->   foo varchar(25),        ->   bar int);

After doing the "GRANT ALL PRIVLEDGES.......... I tried my servlet again.
Works perfectly.
          
                
0
 
bhessionAuthor Commented:
I think this deserves the points as it really answered my question and lead the way for me to finding a solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now