Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: No suitable driver found

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    My Mood
    Dead
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default No suitable driver found

    I'm new the JSP/Servlets/GlassFish/MySQL (I'm doing this in my free time.) I can't seem to get my MySQL DB connected to my Servlet and my Servlet connected to my JSP page. I've looked up some tutorials but I have not found a solution.

    Here is what I have installed:
    MySQL DB (newest)
    NetBeans IDE EE (newest)
    GlassFish (newest)


    I'm not sure how to do any of this

    Here are my sources:
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
        <head>
            <link rel="stylesheet" type="text/css" href="css/main.css" />
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Index</title>
        </head>
        <body>
            <h1>Index</h1>
        </body>
    </html>

    root { 
        display: block;
    }
     
    body {
        text-align: center;
        font: 12px sans-serif;
    }
     
    h1 {
        text-align: center;
        font: 24px sans-serif;
    }

    import java.io.IOException;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
     
    public class DBConnect extends HttpServlet {
     
        Connection conn;
     
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
        }
     
        @Override
        public void init() {
            try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
            } catch (InstantiationException ex) {
                System.err.println(ex.getMessage());
            } catch (IllegalAccessException ex) {
                System.err.println(ex.getMessage());
            } catch (ClassNotFoundException ex) {
                System.err.println(ex.getMessage());
            }
     
            try {
                conn = DriverManager.getConnection("jdbc:mysql//localhost:3306/", "root", "root");
            } catch (SQLException ex) {
                System.err.println(ex.getMessage());
            }
        }
     
        @Override
        public void destroy() {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException ex) {
                System.err.println(ex.getMessage());
            }
        }
    }

    Here are the warnings/errors I get:
    SEVERE: com.mysql.jdbc.Driver
    SEVERE: No suitable driver found for jdbc:mysql//localhost:3306/

    Any help is appreciated, thank you.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: No suitable driver found

    You need to add the JDBC MySQL driver to your classpath:
    MySQL :: MySQL Connectors

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    My Mood
    Dead
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: No suitable driver found

    Thanks for the tip: I've Google'd and followed some tutorials and have added the proper JAR's to my IDE and what-not.

    Now I am getting the second error/warning

    EDIT: I fixed it! It was my syntax
    Last edited by Josheh; October 16th, 2011 at 01:16 AM.

Similar Threads

  1. [SOLVED] Issues with a test driver file
    By Gthoma2 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 18th, 2011, 07:54 PM
  2. Link From A Driver Class To The Subclasses
    By angels in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 29th, 2011, 07:39 AM
  3. Replies: 2
    Last Post: November 25th, 2010, 01:59 PM
  4. setting JDBC driver steps
    By planmaster in forum JDBC & Databases
    Replies: 1
    Last Post: November 6th, 2010, 02:02 PM
  5. How to install a JDBC driver in Eclipse? And where to take it from?
    By noFear in forum Java Theory & Questions
    Replies: 2
    Last Post: August 17th, 2010, 10:51 AM