Results 1 to 17 of 17
  1. #1
    danghieu is offline Member
    Join Date
    Apr 2010
    Posts
    11
    Rep Power
    0

    Default failed to connect to DB

    I'm trying to connect to Access. but it's always send me a problem that :"failed to connect to DB". i don't know how to solve, someone told me that it's a problem about default password and account . ... i don't know :( help me please . thanks

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    danghieu is offline Member
    Join Date
    Apr 2010
    Posts
    11
    Rep Power
    0

    Default

    here is all i have done
    package project_java;
    import java.sql.*;
    public class thuxem {
    public static void main(String args[] ){
    Connection con=null;
    try{
    String driver="sun.jdbc.odbc.JdbcOdbcDriver";
    String url="jdbc: odbc:db1odbc";
    Class.forName(driver);
    con = DriverManager.getConnection(url,"root","");
    }
    catch (ClassNotFoundException e)
    {
    System.out.println("khong tim thay driver");
    }
    catch (SQLException e)
    {
    System.out.println("Khong ket noi duoc voi co so du lieu");
    }

    }

    }

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

    Default

    Quote Originally Posted by danghieu View Post
    here is all i have done
    In that last catch-block could you insert an e.printStackTrace() call and show us its output?

    kind regards,

    Jos

  5. #5
    danghieu is offline Member
    Join Date
    Apr 2010
    Posts
    11
    Rep Power
    0

    Default

    hereeeeeeeeeeeeee :|
    java.sql.SQLException: No suitable driver found for jdbc: odbc:db1odbc
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at project_java.thuxem.main(thuxem.java:10)

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

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

    Default

    Quote Originally Posted by danghieu View Post
    hereeeeeeeeeeeeee :|
    Your driver is stored in a .jar file somewhere; put that .jar file in your classpath. Or else check that URL; does it really have spaces in it?

    kind regards,

    Jos

  8. #8
    danghieu is offline Member
    Join Date
    Apr 2010
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Your driver is stored in a .jar file somewhere; put that .jar file in your classpath. Or else check that URL; does it really have spaces in it?

    kind regards,

    Jos
    i used searching in window to find out the classpath but .... :-??

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

    Default

    Forget about my previous reply: I just noticed that you're using the jdbc-odbc bridge and that one comes with your Java distribution; I googled a bit and saw that you have to install it as:

    Class.forName( ... ).newInstance(), i.e. you have to instantiate a driver object, not just load the class.

    kind regards,

    Jos
    Last edited by JosAH; 05-24-2010 at 04:52 PM.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    You alos appear to have a space in the middle of your connection string:
    "jdbc: odbc:db1odbc"

    That would get you an no valid driver exception even with the jar file in the classpath.

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

    Default

    Quote Originally Posted by Tolls View Post
    You alos appear to have a space in the middle of your connection string:
    "jdbc: odbc:db1odbc"

    That would get you an no valid driver exception even with the jar file in the classpath.
    Yep, I also noticed that (see reply #7) but this bloody forum software also inserts spaces spontaneously; I think it's the lack of the newInstance() method call; that seems to be the way that bridge wants to be installed. Oh well, we'll wait for the net stack trace ;-)

    kind regards,

    Jos

    edit: forget about that newInstance() too; the fault is that space in your URL.
    Last edited by JosAH; 05-24-2010 at 05:24 PM.

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    I've seen it in the stacktraces before, but it's also in the code...so I suspect it's real.

  13. #13
    danghieu is offline Member
    Join Date
    Apr 2010
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Forget about my previous reply: I just noticed that you're using the jdbc-odbc bridge and that one comes with your Java distribution; I googled a bit and saw that you have to install it as:

    Class.forName( ... ).newInstance(), i.e. you have to instantiate a driver object, not just load the class.

    kind regards,

    Jos
    like this :

    package project_java;
    import java.sql.*;
    public class thuxem {
    public static void main(String args[] ){
    Connection con=null;
    try{
    String driver="sun.jdbc.odbc.JdbcOdbcDriver";
    String url="jdbc:odbc:db1odbc";
    Class.forName(driver).newInstance();// unhandled exceptiontype
    con = DriverManager.getConnection(url,"root","");
    }
    catch (ClassNotFoundException e)
    {
    System.out.println("khong tim thay driver");
    }
    catch (SQLException e)
    {
    System.out.println("Khong ket noi duoc voi co so du lieu");
    e.printStackTrace();
    }

    }

    }
    but it show the error that" unhandled exceptiontype"

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

    Default

    Quote Originally Posted by danghieu View Post
    like this :



    but it show the error that" unhandled exceptiontype"
    I updated my previous reply, but: forget about that newInstance() method call. If you have removed that space character from your URL, try again.

    kind regards,

    Jos

  15. #15
    danghieu is offline Member
    Join Date
    Apr 2010
    Posts
    11
    Rep Power
    0

    Default

    no no, i make space there because when i type ":"+"o" = :o it's a fun image. so it's not problem :|

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    That's why you should use CODE tags, and not QUOTE tags.

  17. #17
    danghieu is offline Member
    Join Date
    Apr 2010
    Posts
    11
    Rep Power
    0

    Default

    thanks to all of you. i solved my problem.
    i had to create a connection with access through Data Source in windows. and my url is "jdbc:odbc:db1" ("db1" is name of connection i created in data source)
    :)

Similar Threads

  1. JVM creation failed
    By RogerP in forum NetBeans
    Replies: 12
    Last Post: 10-08-2011, 09:33 PM
  2. Replies: 0
    Last Post: 03-18-2010, 05:39 PM
  3. my Quicksort attempt has failed
    By Jeremy8 in forum New To Java
    Replies: 4
    Last Post: 11-16-2009, 02:56 AM
  4. Failed in reading xml
    By gayathri_g in forum New To Java
    Replies: 0
    Last Post: 08-27-2009, 02:07 PM
  5. failed to connect to remote vm
    By plummer in forum Eclipse
    Replies: 1
    Last Post: 05-08-2009, 08:11 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
  •