Results 1 to 10 of 10
  1. #1
    gerard kowara is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default java connection to mssql

    Hi All,

    I try to write a simple java application, which enable user to connect to microsoft sql server,
    I write this aplication using netbean
    But the thing is the application itself unable to connect itself to MS SQL Server,

    here is the folowing code:
    driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver" ;
    url = "jdbc:odbc:callpartner";
    Class.forName(driver);
    connection = (Connection) DriverManager.getConnection(url,"username","passwo rd");

    any idea what's going on here
    please help me
    Thx

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Yeah, you're loading the MS SQL Server Driver and attempting to use the ODBC-JDBC Bridge, rather than MS SQL Server JDBC Driver. Read the Documentation for that Driver and change your "url" variable accordingly.

  3. #3
    gerard kowara is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default

    Dear Masjide,

    I don't get it,
    please apologize me, coz i'm new in java world
    according to my understanding is
    1)I have to load the jdbc driver
    i allready do it with the code
    driver = "sun.jdbc.odbc.JdbcOdbcDriver"
    or
    driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"

    my question is, is it possible that perhaps those driver is not exist in my computer?
    if my driver is not exist,
    how to download it?
    which site i can go to get those driver?

    Thank you very much for your fast response,
    is really helpful

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Yes, you have to load the dirver (well if you have Java 6 and the driver jarfile is configured and included properly, you don't but we won't get into that). But this code
    Java Code:
    driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver" ;
    is loading the MS SQL JDBC Driver, which you should be using, and this code
    Java Code:
    url = "jdbcdbc:callpartner";
    attempts to use the JDBC-ODBC Bridge (which is, essentially, a different driver from the one you loaded).

    Like I said, read the documentation for the MS SQL JDBC Driver (and/or download it if you need to) and correct your "url" accordingly.

  5. #5
    gerard kowara is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default

    How about if the code is:
    driver = "sun.jdbc.odbc.JdbcOdbcDriver" ;
    url = "jdbcdbc:odbc:callpartner";

    well i used that just now,
    But the result is not good,
    this is how i do it:
    step 1)
    with the code above, i try to login with incorrect pasword
    well the result is realy surprising me cozz the message box is come out with comment:
    [MICROSOFT] [ODBC SQL SERVER] [SQL SERVER] Login failed for user "sa"
    This comment remind me that the application, is able to detect wheter i'm using a corect password or not,
    which in other word the application at least try to connect to a target database, well it is a good news

    step2)
    with this step i using to log in with correct password,
    but the result is not good, in other word the application keep waiting for connection to be made,
    no message box come out, since i'm using "try and catch mechanism"

    For your info, i using netbean and jdk1.6,
    and for the code url = "jdbcdbc:odbc:callpartner";
    the word "callpartner", is a data source name,

    can you tell me what went wrong?
    why the outcome between those two step are diffrent

    Thank you very much

  6. #6
    gerard kowara is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default

    Well thanks for your attention,
    It's getting dark soon, in my place
    i got to go back
    i will continue tomorrow, i will let you know the outcome

    Thank you very much

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    If you wish to use the JDBC-ODBC Bridge, yes, but I highly recommend you don't.

    You need to (at least eventually) learn about the urls and drivers anyway, take advantage of the situation and learn about them and this will never be a problem again. If I simply tell you what the url (and/or driver classname) should be you'll change it without learning about what it is or why it should change and so will make the same mistake again and again.

  8. #8
    gerard kowara is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default java connection to mssql

    Hi Masijade

    thanks for your time and answer
    my problem is solved already
    to solve this problem,i need to download "Microsoft SQL Server 2005 JDBC Driver"
    and include that into my application code accordingly.
    since i'm using netbean, the addition process is very much straightforward and simple

    By the way just for my info, why jdbc:odbc bridge is highly not recomended?

    Thank You

  9. #9
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    It is not thread safe, it does not fully support all JDBC features (especially not version 4 feratures) and is not, essentially, platform independent, as you still need the appropriate ODBC Driver installed and those are platform dependent (well, not really, they provide a "common" interface, but the Driver itself is native code so a different one needs to be produced for each platform).

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

    Default

    Because it's an ancient driver that was created before the various db vendors had written their db specific versions, in order to provide a basic test version for people to write JDBC code against. It was a bad idea to use it 10 years ago, it's an even worse idea now.

Similar Threads

  1. Java.net.socket connection :connection closed
    By veeru541 in forum Advanced Java
    Replies: 2
    Last Post: 06-27-2010, 02:14 AM
  2. getinng data from mssql server 2008
    By fcciko in forum JDBC
    Replies: 3
    Last Post: 04-21-2010, 01:59 PM
  3. Connection In Java
    By SaraHrry in forum Advanced Java
    Replies: 7
    Last Post: 01-08-2010, 05:47 PM
  4. java mysql connection
    By sysout in forum New To Java
    Replies: 5
    Last Post: 10-31-2009, 10:48 AM
  5. Not able to delete MSSql database table entries
    By wickedrahul9 in forum Advanced Java
    Replies: 3
    Last Post: 10-17-2008, 12:14 PM

Posting Permissions

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