Results 1 to 16 of 16
  1. #1
    M.Tariq is offline Member
    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Default DataBase Exception: No Suitable driver found

    I have recently switched from C# to Java that why I am very new to java programming. I am trying to write program to learn database connections in java but the I am getting following exceptions while executing my program.

    No suitable driver found for jdbc:derby://localhost:1727/dtbs

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package javaconsole;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    /**
     *
     * @author Prince
     */
    public class JavaConsole {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            String host="jdbc:derby://localhost:1727/dtbs";
            String user="root";
            String password="root";
            try{
                Connection cnn=DriverManager.getConnection(host,user,password);
                System.out.println("Connection Established Successfully!");
            }
            catch(SQLException se){
                System.out.println(se.getMessage());
            }
        }
    }
    I am using NetBeans IDE.

  2. #2
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    384
    Rep Power
    4

    Default Re: DataBase Exception: No Suitable driver found

    I don't use NetBeans, so I'm not sure if it's installed by default, but you probably have to download and install the Derby JDBC. A quick Google found this page: Derby JDBC driver

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: DataBase Exception: No Suitable driver found

    Toll is correct - no DB connectors come by default. Grab the jar file Tolls mentions, and add it to the Library section of the project properties. This references the libs you need for building and runtime. If you wish to deploy your app somewhere, you will need to bundle the jdbc and any other libs you use with the jar.

  4. #4
    M.Tariq is offline Member
    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Default Re: DataBase Exception: No Suitable driver found

    NetBeans service browser show a data base (or data source as in C#) tree containing my database 'dtbs'. And the driver subtree contains a node named "MySQL Connector (J Driver)". Also in the NetBeans's plugin dialog box contains a plugin for JDB. So it seems that the base IDE it self contains the driver but still I did What you told to me. I downloaded the latest derby driver and included the jar file as well as the complete folder in the project properties but the result is same Exception.DataBase Exception: No Suitable driver found-untitled.png

  5. #5
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,828
    Rep Power
    19

    Default Re: DataBase Exception: No Suitable driver found

    That's Netbeans, not your project.
    Your project needs the driver as well.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    M.Tariq is offline Member
    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Default Re: DataBase Exception: No Suitable driver found

    You mean some thing like this:
    DataBase Exception: No Suitable driver found-untitled.png
    Well this is again not working. You can read the exception in output window in the

  7. #7
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    384
    Rep Power
    4

    Default Re: DataBase Exception: No Suitable driver found

    I think the Derby driver is called derbyclient.jar, not derby.jar. See if you've got a file like that to include.

  8. #8
    M.Tariq is offline Member
    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Default Re: DataBase Exception: No Suitable driver found

    Yeah I think I am a step forward now! here is a new exception encountered!

    java.net.ConnectException : Error connecting to server localhost on port 1727 with message Connection refused: connect.

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default Re: DataBase Exception: No Suitable driver found

    A DriverManager doesn't know where to look for jdbc drivers; those drivers have to register themselves at the manager; do something like this before you ask the DriverManager to hand you over a driver:

    Java Code:
    Class.forName("org.apache.derby.jdbc.<XXX>Driver");
    where <XXX> is "Embedded" or "Client" depending on your needs.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    M.Tariq is offline Member
    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Default Re: DataBase Exception: No Suitable driver found

    Sorry! I dont understand what you want to say. Can you please explain this in a bit detail. Actually I am new to java.

  11. #11
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    384
    Rep Power
    4

    Default Re: DataBase Exception: No Suitable driver found

    With that last error message, it seems the driver is working at least. One thing I noticed though: In your screenshot, the port is 1527. The error message says 1727. Make sure you're not using the wrong port.

  12. #12
    M.Tariq is offline Member
    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Default Re: DataBase Exception: No Suitable driver found

    Yes that was my mistake! But Now I got the same error with the same port i.e. 1527.

  13. #13
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,828
    Rep Power
    19

    Default Re: DataBase Exception: No Suitable driver found

    Quote Originally Posted by JosAH View Post
    A DriverManager doesn't know where to look for jdbc drivers; those drivers have to register themselves at the manager; do something like this before you ask the DriverManager to hand you over a driver:

    Java Code:
    Class.forName("org.apache.derby.jdbc.<XXX>Driver");
    That's no longer the case, not since 1.6.
    They get registered automatically if they are JDBC4 compliant.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #14
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default Re: DataBase Exception: No Suitable driver found

    Quote Originally Posted by Tolls View Post
    That's no longer the case, not since 1.6.
    They get registered automatically if they are JDBC4 compliant.
    But how does a DriverManager know what driver to install? If a JDBC implementation has a DataSource available no DriverManager is needed, but otherwise I don't understand how it should be done ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,828
    Rep Power
    19

    Default Re: DataBase Exception: No Suitable driver found

    From the DriverManager API:
    "
    The DriverManager methods getConnection and getDrivers have been enhanced to support the Java Standard Edition Service Provider mechanism. JDBC 4.0 Drivers must include the file META-INF/services/java.sql.Driver. This file contains the name of the JDBC drivers implementation of java.sql.Driver.
    "
    It basically trawls the classpath.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  16. #16
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default Re: DataBase Exception: No Suitable driver found

    Ah, of course; I should've known; thanks. That's the same mechanism they use for those ScriptEngines ...

    kind regards.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Connecting to Database - No Suitable Driver Found
    By Humphrey Bogart in forum New To Java
    Replies: 3
    Last Post: 10-09-2012, 09:59 AM
  2. MySQL: No suitable driver found.
    By Onra in forum JavaServer Pages (JSP) and JSTL
    Replies: 8
    Last Post: 12-15-2011, 02:41 PM
  3. No suitable driver found
    By chinna in forum New To Java
    Replies: 3
    Last Post: 11-30-2011, 01:17 PM
  4. No suitable driver found exception error
    By Crazy Caveman in forum Networking
    Replies: 1
    Last Post: 09-01-2010, 12:03 AM
  5. No suitable driver found
    By geekchick in forum New To Java
    Replies: 2
    Last Post: 08-25-2010, 12:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •