| Author |
Error in Connecting to SQL Server 2000 database
|
mohsin sheikh
Greenhorn
Joined: Mar 28, 2007
Posts: 22
|
|
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
Joined: Mar 28, 2007
Posts: 391
|
|
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
|
Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
|
 |
mohsin sheikh
Greenhorn
Joined: Mar 28, 2007
Posts: 22
|
|
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
Joined: Feb 19, 2008
Posts: 2896
|
|
|
See whether "attendance" database/DSN exist or not
|
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
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).
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
mohsin sheikh
Greenhorn
Joined: Mar 28, 2007
Posts: 22
|
|
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
Joined: Apr 14, 2004
Posts: 10336
|
|
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
Joined: Feb 19, 2008
Posts: 2896
|
|
Hi Paul,
What about the port number and chances of its being block by firewall ?
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
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
Joined: Mar 28, 2007
Posts: 22
|
|
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
Joined: Apr 14, 2004
Posts: 10336
|
|
You get that error for one of two reasons:
There is no JDBC driver in your classpathThe 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
Joined: Mar 28, 2007
Posts: 22
|
|
|
Please tell me about the jar files to be included in Classpath and from where i can download that?
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Here it is.
|
 |
mohsin sheikh
Greenhorn
Joined: Mar 28, 2007
Posts: 22
|
|
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
Joined: Apr 14, 2004
Posts: 10336
|
|
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
Joined: Mar 28, 2007
Posts: 22
|
|
|
No.But i used Avast antivirus
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
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.
|
 |
 |
|
|
subject: Error in Connecting to SQL Server 2000 database
|
|
|