Results 1 to 10 of 10
Thread: java connection to mssql
- 10-13-2010, 10:59 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
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
- 10-13-2010, 11:02 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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.
- 10-13-2010, 11:17 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
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
- 10-13-2010, 11:25 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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
is loading the MS SQL JDBC Driver, which you should be using, and this codeJava Code:driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver" ;
attempts to use the JDBC-ODBC Bridge (which is, essentially, a different driver from the one you loaded).Java Code:url = "jdbcdbc:callpartner";
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.
- 10-13-2010, 11:47 AM #5
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
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
- 10-13-2010, 11:54 AM #6
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
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
- 10-13-2010, 12:53 PM #7
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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.
- 10-14-2010, 08:15 AM #8
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
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
- 10-14-2010, 09:06 AM #9
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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-14-2010, 09:07 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Java.net.socket connection :connection closed
By veeru541 in forum Advanced JavaReplies: 2Last Post: 06-27-2010, 02:14 AM -
getinng data from mssql server 2008
By fcciko in forum JDBCReplies: 3Last Post: 04-21-2010, 01:59 PM -
Connection In Java
By SaraHrry in forum Advanced JavaReplies: 7Last Post: 01-08-2010, 05:47 PM -
java mysql connection
By sysout in forum New To JavaReplies: 5Last Post: 10-31-2009, 10:48 AM -
Not able to delete MSSql database table entries
By wickedrahul9 in forum Advanced JavaReplies: 3Last Post: 10-17-2008, 12:14 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks