开发者

How do I get started using JDBC and SQL Server 2008 R2?

开发者 https://www.devze.com 2023-03-25 04:04 出处:网络
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 authentic

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 def开发者_开发技巧ine 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!


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.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号