File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes SQL Server DB connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "SQL Server DB connection" Watch "SQL Server DB connection" New topic
Author

SQL Server DB connection

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

I am working with the following method trying to get a database connection to the sql server on my local PC:

public void testMS(){
Connection con = null;
String hostname = "THR0011432AE125"; // my machine
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://"+ hostname +":1433");
Statement stmt = con.createStatement();
ResultSet rs= stmt.executeQuery("SELECT * FROM CUSTOMERS");
while (rs.next()) {
String field = rs.getString(1);
String data = rs.getString(2);
// Do something like System.out.println(mykeyfield);
System.out.println("Field: " + field + " Value: " + data);
}

} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
if(con != null){
try { con.close(); }
catch (Exception e) {System.out.println("Error closing connection: " + e.getMessage());
}
}
}
}

However, I am getting the following error:

[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.

I setup my local sql server to accept windows authentication instead of setting up a sql username and password. Is there any way to code to allow my windows authentication to be used for security purposes to connect to my local sql server?

Any help or direction would be appreciated.

Thanks.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Is there any way to code to allow my windows authentication to be used for security purposes to connect to my local sql server?

No. You have to use SQL Server authentication.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

Paul,

Thanks so much for the quick response. Appreciate your help.

Regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL Server DB connection
 
Similar Threads
No access to SQL Express 2005/2008 database
HELP - newbie question on JDBC
Newbie help please on SQL connection problem
Problem with Connectivity
SQL Server Connection question