JDBC driver for SQL Server

If I install SQL Server do I get with it any JDBC driver or do I have to install it seperately.
If it comes with SQL Server please tell me where can I find it and if does not come with SQL Server then please tell me from where to download it.
LVL 8
thomas908Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
There should be a driver. If not, then you can use

http://jtds.sourceforge.net/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sham HaqueSenior SAP CRM ConsultantCommented:
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

objectsCommented:
u need to install it seperately

http://msdn2.microsoft.com/en-us/data/aa937724.aspx
0
thomas908Author Commented:
0
thomas908Author Commented:
>>or use a JDBC-ODBC bridge
>>http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/bridge.doc.html

I guess, I'll have to create a DSN for this but I'd prefer installing a Java driver than creating a DSN. Please correct me if I am wrong
0
thomas908Author Commented:
I came across this link

http://www.microsoft.com/downloads/details.aspx?familyid=9f1874b6-f8e1-4bd6-947c-0fc5bf05bf71&displaylang=en

But it talks about installing from a exe. Can't i get a jar file which I can put in my tomcat lib and get started, like there is classes12.jar in case of Oracle.
0
objectsCommented:
> We are using SQL Server 2000

see the 2nd link posted by jaax
0
objectsCommented:
> But it talks about installing from a exe.

the exe includes the jars
0
Sham HaqueSenior SAP CRM ConsultantCommented:

thomas908:
>>or use a JDBC-ODBC bridge
>>http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/bridge.doc.html

>>I guess, I'll have to create a DSN for this but I'd prefer installing a Java driver than creating a DSN. Please correct me if I am wrong

you are wrong. no dsn needed - just means a slightly longer conn string.
eg: jdbc:odbc:Driver={SQL Server};Server=myServer;Database=myDB;
0
thomas908Author Commented:
>>you are wrong. no dsn needed - just means a slightly longer conn string.
>>eg: jdbc:odbc:Driver={SQL Server};Server=myServer;Database=myDB;

This doesn't work.
Class.forName ( "sun.jdbc.odbc.JdbcOdbcDriver" ) ;
            Connection con = DriverManager.getConnection("jdbc:odbc:Driver={SQL Server};Server=192.168.10.15;Database=myDB;");

Please let me know what else to add? Where to add user name and password.            
0
thomas908Author Commented:
Even this doesn't work

Connection con = DriverManager.getConnection("jdbc:odbc:Driver={SQL Server};Server=192.168.10.15;Database=myDB;", "sa", "sa");
0
objectsCommented:
u don't  need/want to use odbc, download the jdbc driver from ms and use it
0
thomas908Author Commented:
>>u don't  need/want to use odbc, download the jdbc driver from ms and use it
Is there any disadvantage of using odbc.
I need to make DB connection in just one Servlet.
0
objectsCommented:
the bridge is only intended for testing, its not a production grade driver.
0
mrcoffee365Commented:
We use both the odbc and the native SQL Server drivers, and we have not had problems with either of them.  "objects" is right in the sense that if you need a high-performance solution, then the native driver should be faster.

For connecting, there are a lot of ways to do it, but we use this successfully with an odbc driver:

Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
Connection con = DriverManager.getConnection( "jdbc:odbc:oursystemdsnname", "username", "password" );
0
Mayank SAssociate Director - Product EngineeringCommented:
>> Is there any disadvantage of using odbc.

Yes, performance as coffee pointed out - because you will add an additional layer (the ODBC bridge/ driver).

>> see the 2nd link posted by jaax
>> the exe includes the jars

Also make sure you add the 3 JARs (msutil.jar, msbase.jar and mssqlserver.jar) to the classpath.
0
thomas908Author Commented:
I have downloaded the 3 jar files. But this is not working

String dbDriverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String host = properties.getProperty("Host");      
String port = properties.getProperty("Port");
                 
            
try {
Class.forName(dbDriverName);
Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://"+host+":"+port,"sa","sa");      

}catch (ClassNotFoundException cnfe) {
      cnfe.printStackTrace();
}
catch (SQLException sqle) {
      sqle.printStackTrace();
}

Do I need to make some changes?
0
thomas908Author Commented:
The error I am getting is

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establis
hing socket.
        at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source
)
        at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
        at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
        at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)

        at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Sou
rce)
        at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown S
ource)
        at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
        at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
        at java.sql.DriverManager.getConnection(DriverManager.java:512)
        at java.sql.DriverManager.getConnection(DriverManager.java:171)
        at com.documentum.admin.AdminOperation.doGet(AdminOperation.java:27)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:214)

0
mrcoffee365Commented:
You didn't give the port on which SQL Server is listening, which by default is 1433 but might be different for your configuration.  

This kb article from Microsoft is a good one for successfully creating a connection using the native MS SQL Server driver.
http://support.microsoft.com/kb/313100

Also, by default usually the sa user doesn't have a password.  So you might have to put "sa","".  Or, your configuration has specified a good password, in which case it isn't as likely to be "sa".  It would be good to double-check the username and password you are using for the connection.
0
thomas908Author Commented:
I did this
connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://"+host+":"+port,"sa","sa");      
I think the connection is established correctly but how to specify which database we need to connect to. I have more than one database on the same SQL Server.
0
thomas908Author Commented:
Sorry had to do
DriverManager.getConnection("jdbc:microsoft:sqlserver://"+host+":"+port+";databaseName="+databaseName);      

was there in the article
0
mrcoffee365Commented:
So you got it working?  That's great!
0
Mayank SAssociate Director - Product EngineeringCommented:
>> DriverManager.getConnection("jdbc:microsoft:sqlserver://"+host+":"+port+";databaseName="+databaseName);      

Yes the databaseName is to be specified so that it knows which schema to hit.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.