This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in Connecting to SQL Server 2000 database

 
mohsin sheikh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am building a project in struts.I am using Sql Server 2000 database for backend.
I am getting an exception of"No Suitable Driver" when i am trying to connect to database.
I have successfully build the User DSN say "attendance" using ODBC.
I have used following driver to connect to database:

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
DriverManager.getConnection("jdbc:odbc:attendance","sa","");

Please tell me where i am going wrong.
Please guide me to connect to database.

ThankYou.
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Did you include the sqljdbc jar file in libraries ? Kindly check for sqljdbc.jar file in your project's lib folder, if its not there

you can get it from

http://www.microsoft.com/downloads/details.aspx?familyid=e22bc83b-32ff-4474-a44a-22b6ae2c4e17&displaylang=en
 
mohsin sheikh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ujwal thanks for your help.
I have included sqljdbc.jar in the path but that doesn't work.
I change the code to:

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con=DriverManager.getConnection("jdbc:sqlserver://localhost;databaseName=attendance","sa","");

Now it is giving an error:
Unable to Initialize Data Source (com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect)

Please help.

Is there any other way to connect to SQL Server 2000?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See whether "attendance" database/DSN exist or not
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A DSN should not be required. Why do you want to use ODBC?

Make sure your database instance is configured to accept connections over TCP/IP (for SQL Server 2000 this should be the default case) and make sure it is configured to support SQL Server authentication (by default this is not the case).
 
mohsin sheikh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi paul,

Can you tell me how to progress.
can you give me a code to connect.I am not using ODBC
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am not using ODBC

Ah - re-read your second post. I just noticed you were using ODBC in your initial question. Sorry.


Can you tell me how to progress.
can you give me a code to connect

Your code looks OK. Have you checked the configuration of your server for the things I suggested?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
What about the port number and chances of its being block by firewall ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would be very surprised if the port number had been changed and in that instance I'd expect the connection to time out, rather than being refused. The exception message would also be different if a Firewall prevented it - the message would be something like "software caused connection abort". Given SQL Server 2000 is not configured to accept connections using SQL Server authentication by default I would think my second suggestion is the more likely one.
 
mohsin sheikh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The error of TCP/IP has been removed.Now I am getting an error of:
No Suitable Driver for jdbc:sqlserver://localhost;databaseName=attendance","sa",""

Which type of Driver it is talking about.Can you explain..I have included sqljdbc.jar in the libraries but still i am getting the above error.
Can you tell me about driver.
Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You get that error for one of two reasons:
  • There is no JDBC driver in your classpath
  • The JDBC url you are using is not one supported by any of the drivers in your classpath


  • Reading the driver documentation the syntax for the urls is:

    so your URL looks OK, which means you must not have the driver jar files in your classpath.
     
    mohsin sheikh
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Please tell me about the jar files to be included in Classpath and from where i can download that?
     
    Paul Sturrock
    Bartender
    Posts: 10336
    Eclipse IDE Hibernate Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Here it is.
     
    mohsin sheikh
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I am getting the error:
    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.

    I have included all jar file.I have checked that TCP/IP is enabled in my system.My system is a standalone computer which is not connected to any network.Please help me in resolving the problem
     
    Paul Sturrock
    Bartender
    Posts: 10336
    Eclipse IDE Hibernate Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    mohsin sheikh wrote:I am getting the error:
    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.

    I have included all jar file.I have checked that TCP/IP is enabled in my system.My system is a standalone computer which is not connected to any network.Please help me in resolving the problem


    Do you use a firewall?
     
    mohsin sheikh
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    No.But i used Avast antivirus
     
    Paul Sturrock
    Bartender
    Posts: 10336
    Eclipse IDE Hibernate Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Check that is not stopping the connection. Also worth checking what patch level SQL Server is at, some (very early) versions had issues in their tcp/ip DLLs.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic