Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using SQL Server 2005 jdbc

 
Paul O'Neill
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the driver name for the old SQLServer 2000 driver; see here.

The new one is different.
 
Paul O'Neill
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry. I *am* using the new version. Typo on my part.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Paul O'Neill
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic