Getting "SQLException: No suitable driver" when trying to connect to mysql from eclipse

Discussion in 'Java' started by jborup, Feb 3, 2007.

  1. jborup

    jborup Guest

    Hi community,,,
    I hope you can help. I do believe this is small problem. I have seen
    the problem raised several places at the net, but not found a
    solution.

    I want to connect to a mysql db on a server, from the client where I
    do the development. Its done in java, using the eclipse ide, its just
    a small 'hello world' type stand alone java program. I have used some
    sample code, and when I compile I get "SQLException: No suitable
    driver". From searching the internet, the problem should be, that I
    don't have the mysql jar file in my path. To "my project" ->
    properties -> Libraries, I have added a external jar, and selected the
    mysql. jar (running ubuntu - found the jar file in: /usr/share/java/
    mysql.jar). When running then program I still get the error.
    I have also tried from within the class, right click, select 'run as' -
    > run, some run configurations appears. In the classpath I have added

    the mysql.jar as a external jar. I still get the 'No suitable driver'.

    You could think, that the driver is bad, but from the 'Database
    development' perspective, using the mysql.jar, I have created a
    connection to the server, which logs on, and shows the tables in the
    db. So I guess the driver is ok,

    My develoment client, is running ubuntu, eclipse 3.2.1, Mysql driver
    4.x (guess its jdbc 3?)

    This is the sample code:

    // import static java.lang.System.out.*;
    import static java.lang.System.out;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;

    public class HelloWorld {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.println("Hello World");


    try {
    Connection conn =
    DriverManager.getConnection("jdbc:mysql://<server>:3306/
    BudgetDev?"+

    "user=<user>&password=<password>");

    } catch (SQLException ex) {
    // handle any errors
    System.out.println("SQLException: " + ex.getMessage());
    System.out.println("SQLState: " + ex.getSQLState());
    System.out.println("VendorError: " + ex.getErrorCode());
    }


    }

    }

    Hope some can help.
     
    jborup, Feb 3, 2007
    #1
    1. Advertising

  2. Re: Getting "SQLException: No suitable driver" when trying to connectto mysql from eclipse

    jborup wrote:
    > public static void main(String[] args) {
    > // TODO Auto-generated method stub
    > System.out.println("Hello World");
    >
    >
    > try {


    Class.forName("com.mysql.jdbc.Driver");

    > Connection conn =
    > DriverManager.getConnection("jdbc:mysql://<server>:3306/
    > BudgetDev?"+
    >
    > "user=<user>&password=<password>");


    Arne
     
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Feb 3, 2007
    #2
    1. Advertising

  3. jborup

    jborup Guest

    Thank you.....

    Than solved the problem.
    Regards Jørn Borup

    On 3 Feb., 16:03, Arne Vajhøj <> wrote:
    > jborup wrote:
    > > public static void main(String[] args) {
    > > // TODO Auto-generated method stub
    > > System.out.println("Hello World");

    >
    > > try {

    >
    > Class.forName("com.mysql.jdbc.Driver");
    >
    > > Connection conn =
    > > DriverManager.getConnection("jdbc:mysql://<server>:3306/
    > > BudgetDev?"+

    >
    > > "user=<user>&password=<password>");

    >
    > Arne
     
    jborup, Feb 4, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JD Uhler
    Replies:
    5
    Views:
    6,733
    Thomas Fritsch
    Feb 4, 2004
  2. jborup
    Replies:
    1
    Views:
    649
  3. laredotornado
    Replies:
    2
    Views:
    5,074
    Roedy Green
    Oct 25, 2009
  4. Allen Marshall
    Replies:
    1
    Views:
    193
    Gunnar Hjalmarsson
    Jan 24, 2004
  5. Replies:
    6
    Views:
    128
Loading...

Share This Page