*
The moose likes JDBC 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Using SQL Server 2005 jdbc" Watch "Using SQL Server 2005 jdbc" New topic
Author

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("com.microsoft.jdbc.sqlserver.SQLServerDriver", 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
Marshal

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

The new one is different.


Ping & DNS - my free Android networking tools app
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: 3703
    
    5

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 ]

My Blog: Down Home Country Coding with Scott Selikoff
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 = "com.microsoft.sqlserver.jdbc.SQLServerDriver"

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
 
 
subject: Using SQL Server 2005 jdbc
 
Similar Threads
Conditional (Ternary) Operator (?:)
EJB QL & heterogeneous relationships
Need help with BigInteger
StringBuffer / StringBuilder methods
JQuery fade problems