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
bhessionAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.