2

I've been googling this for the last 3 hours, and I've had no luck. I'm trying to connect to a SQL Server 2008 with Java, which I normally access with SQL Management Studio. It's windows authenticated too, so it's not like I enter a username or password.

The two relevent lines of code:

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    Connection conn = DriverManager.getConnection(db_connect_string, db_userid, db_password);

What I want to know is:

  1. What am I supposed to put in for Class.forName? I just downloaded the latest JDBC. Yes I've looked around. Most sites tell me what it is, and why I need to set it, rather than what I need to set.

  2. Where do I define a class path, and what do I define it as? I've googled this, and I can't find anything that tells me WHERE I set this.

  3. Since it's a windows authenticated system, what do I use for db_connect_string, db_userid, and db_password? I'm assuming db_connect_string is localhost, right (if it's a local database)?

I'm not very well versed with any of this, so an explanation would be really appreciated!

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Kris
  • 21
  • 1
  • Partial answer: CLASSPATH is an environment variable; you set it in your windows environment (system properties!advanced!environment or the like). – DwB Aug 04 '11 at 20:47

2 Answers2

0

The Microsoft JDBC driver supports Windows authentication for clients on Windows platforms. Beginning with the 4.0 release, we also offer pure Java Kerberos authentication regardless of platforms. You can find more details on Kerberos here - http://msdn.microsoft.com/en-us/library/gg558122.aspx and setting connection properties here - http://msdn.microsoft.com/en-us/library/ms378988.aspx

Our online help in general provides guidelines for building your connection url and making connections to SQL Server.

0

Actually, you can use JDBC (as well as jTDS) to connect to SQL Server from Java with Windows authentication. Please take a look here. Hope it helps!

Thusi
  • 929
  • 7
  • 5