Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL Server DB connection

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,

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

Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic