Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Connecting to Database - No Suitable Driver Found

    Hello. I'm using NetBeans to build a program to work with a database.

    I have set up a small database and here is the code to access it:
    Java Code:
    package database_console;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.ResultSet;
    
    public class DBConnect {
    
        public static void main(String[] args) {
                   
            String host = ("jdbc://localhost:1527/Employees");
            String uName = ("admin");
            String pWord = ("admin");
            
            try {
                Connection con = DriverManager.getConnection(host, uName, pWord);
                Statement stmt = con.createStatement();
                String SQL = "SELECT * FROM WORKERS";
                ResultSet rs = stmt.executeQuery(SQL);
                
                while (rs.next()) {
                    rs.next();
                    int id_col = rs.getInt("ID");
                    String first_name = rs.getString("First_Name");
                    String last_name = rs.getString("last_Name");
                    String job = rs.getString("Job_Title");
                
                    String out = id_col + " " + last_name + ", " + first_name + " " + job;
                    System.out.println(out);
                }
            }
            
            catch (SQLException err) {
                System.out.print(err.getMessage());
            }
        }
    }
    When I try and run the program, I get the following error.
    No suitable driver found for jdbc://localhost:1527/EmployeesBUILD SUCCESSFUL (total time: 0 seconds)

    I then added the derbyclient.jar file to the project Library, but I continue to get the same error.

    Can anyone suggest how to proceed? Thank you.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default Re: Connecting to Database - No Suitable Driver Found

    You need to use the correct connection string for the driver you are using.
    That connection string matches nothing.
    Look up in the Derby docs for what to use.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Re: Connecting to Database - No Suitable Driver Found

    Hello. Thanks for your reply.

    The line 18 has been truncated when I pasted it into the web page. The complete Line 18 reads:
    Connection con = DriverManager.getConnection(host, uName, pWord)

    The Strings host, uName, and pWord were declared on Lines 13, 14, and 15, respectively, specifying the database address, user name, and password.

    I'm not sure if this is what you are referring to. If you are referring to something else, please let me know.

    One thing I can try is to re-write Line 18 to include address, user name, and password directly.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default Re: Connecting to Database - No Suitable Driver Found

    That host (ie connection url) is wrong.
    You need to use one that is specific for the driver you are using.
    See the Derby docs for what that is.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 5
    Last Post: 03-13-2012, 02:51 PM
  2. MySQL: No suitable driver found.
    By Onra in forum JavaServer Pages (JSP) and JSTL
    Replies: 8
    Last Post: 12-15-2011, 03:41 PM
  3. No suitable driver found
    By chinna in forum New To Java
    Replies: 3
    Last Post: 11-30-2011, 02:17 PM
  4. No suitable driver found exception error
    By Crazy Caveman in forum Networking
    Replies: 1
    Last Post: 09-01-2010, 01:03 AM
  5. No suitable driver found
    By geekchick in forum New To Java
    Replies: 2
    Last Post: 08-25-2010, 01: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
  •