Solved

JDBC driver for SQL Server

Posted on 2007-04-02
24
444 Views
Last Modified: 2012-06-22
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.
0
Comment
Question by:thomas908
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 5
  • 3
  • +4
24 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 18835130
There should be a driver. If not, then you can use

http://jtds.sourceforge.net/
0
 
LVL 10

Accepted Solution

by:
Jaax earned 100 total points
ID: 18835134
0
 
LVL 18

Assisted Solution

by:Sham Haque
Sham Haque earned 100 total points
ID: 18835143
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
ID: 18835150
u need to install it seperately

http://msdn2.microsoft.com/en-us/data/aa937724.aspx
0
 
LVL 8

Author Comment

by:thomas908
ID: 18835153
0
 
LVL 8

Author Comment

by:thomas908
ID: 18835162
>>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
 
LVL 8

Author Comment

by:thomas908
ID: 18835170
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
 
LVL 92

Expert Comment

by:objects
ID: 18835173
> We are using SQL Server 2000

see the 2nd link posted by jaax
0
 
LVL 92

Expert Comment

by:objects
ID: 18835176
> But it talks about installing from a exe.

the exe includes the jars
0
 
LVL 18

Expert Comment

by:Sham Haque
ID: 18835200

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
 
LVL 8

Author Comment

by:thomas908
ID: 18835273
>>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
 
LVL 8

Author Comment

by:thomas908
ID: 18835293
Even this doesn't work

Connection con = DriverManager.getConnection("jdbc:odbc:Driver={SQL Server};Server=192.168.10.15;Database=myDB;", "sa", "sa");
0
 
LVL 92

Expert Comment

by:objects
ID: 18835532
u don't  need/want to use odbc, download the jdbc driver from ms and use it
0
 
LVL 8

Author Comment

by:thomas908
ID: 18835804
>>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
 
LVL 92

Expert Comment

by:objects
ID: 18835826
the bridge is only intended for testing, its not a production grade driver.
0
 
LVL 27

Assisted Solution

by:mrcoffee365
mrcoffee365 earned 100 total points
ID: 18837658
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
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 100 total points
ID: 18837800
>> 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
 
LVL 8

Author Comment

by:thomas908
ID: 18842662
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
 
LVL 8

Author Comment

by:thomas908
ID: 18842747
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
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 18844132
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
 
LVL 8

Author Comment

by:thomas908
ID: 18848771
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
 
LVL 8

Author Comment

by:thomas908
ID: 18848781
Sorry had to do
DriverManager.getConnection("jdbc:microsoft:sqlserver://"+host+":"+port+";databaseName="+databaseName);      

was there in the article
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 18848869
So you got it working?  That's great!
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18860829
>> 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

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question