Solved

JDBC driver for SQL Server

Posted on 2007-04-02
24
413 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
  • 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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 26

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:mayankeagle
mayankeagle 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 26

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 26

Expert Comment

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

Expert Comment

by:mayankeagle
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now