File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Using SQL Server 2005 jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Using SQL Server 2005 jdbc" Watch "Using SQL Server 2005 jdbc" New topic

Using SQL Server 2005 jdbc

Paul O'Neill
Ranch Hand

Joined: Mar 13, 2007
Posts: 40
I've downloaded the SQL Server 2005 file sqljdbc.jar. I've put it into my class path and removed the mssqlserver.jar file that used to be there. I'm connecting with <blockquote>code:
<pre name="code" class="core"> DriverManager.getConnection("", myusername, mypassword) </pre>
</blockquote> but I'm getting this error :
java.sql.SQLException: No suitable driver Is there some other step I need to take. I haven't set up the driver anywhere.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
That's the driver name for the old SQLServer 2000 driver; see here.

The new one is different.
Paul O'Neill
Ranch Hand

Joined: Mar 13, 2007
Posts: 40
I'm sorry. I *am* using the new version. Typo on my part.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

Your syntax is completely wrong. In particular you're mixing registering the driver with getting the connection. Try something more like this:

The first line registers the drive into static memory whereas the second connects to the server.
[ July 18, 2008: Message edited by: Scott Selikoff ]

[OCA 8 Book] [Blog]
Paul O'Neill
Ranch Hand

Joined: Mar 13, 2007
Posts: 40
Apologies again for another typo. I've had a few late nights.
This is the code I'm actually using.

jdbcDriverName = ""

I have included sqljdbc.jar at the top of my classpath and I have removed msbase.jar, msutil.jar and mssqlserver.jar although I also tried this before removing them. I'm using the same url as I did with the 2000 driver. All I need is the jar file right? Once it's on my computer and available in classpath, I don't need to 'execute' it anywhere or set up the driver somehow?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Typos? You should really learn how to copy and paste. Faster and more accurate.

Anyway, yes, the only setup required is to put the jar in your classpath. If it isn't there, then Class.forName will fail and you will get a ClassNotFoundException. Since you aren't getting that, then you are successfully loading the class.

The error message you are getting normally means the JDBC URL isn't understood by any JDBC drivers you have loaded. When you switched to the new SQL Server, did you change the URL to correspond with what it requires?
Paul O'Neill
Ranch Hand

Joined: Mar 13, 2007
Posts: 40
As far as I know, yes. I changed the server piece to match the SQL2005 server. I'm still using port 1433. Here it is :

This is exactly what I have working with SQL2000 except for the server name.
Paul O'Neill
Ranch Hand

Joined: Mar 13, 2007
Posts: 40
Yes, the problem is with the URL. I need to use jdbc:sqlserver:// instead of jdbc:microsoft:sqlserver://

Unfortunately I'm getting a codepage 850 error now.
I agree. Here's the link:
subject: Using SQL Server 2005 jdbc
It's not a secret anymore!