Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why this Program throws SQLException

 
swarupa patil
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers ,
Why this program throws SQLException
Although I put all classes and jar files in class path
the error is

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


import java.sql.*;

class jdbc
{
public static void main(String[] args)
{
try
{

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://209.172.34.240:1433;databaseName=Northwind,user=ossqluser,password=os34sql");
con.close();
System.out.println("Connection Success..!!!");
System.exit(0);
}
catch(ClassNotFoundException eclass)
{
System.out.println("Driver Not Found ! "+eclass);
}
catch(SQLException esql)
{
System.out.println("111 "+esql);//.getMessage());
}
}
}
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.



What authentication method is your SQL instance configured to accept? If you are using the older Microsoft SQL Server driver you have to have the server configured to accept both SQL Server and Windows Integrated authentication, not just Windows Integrated.
 
swarupa patil
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didnot understand ur meaning of
SQL server authentication and windows authentication
Where from we get these both.
Please reply ASAP
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SQL Server 2000 has two methods it can use for authentication. Either Windows Integrated authentication, which authenticates a user based on their NT/AD accounts, or SQL Server authentication which authenticates a user based on the username and password defined as a login on the server instance. The older Microsoft driver can only work with SQL Server authentication so you have to configure your server instance to allow that kind of authentication mechanism. If you are still not sure what I am talking about, or don't know how to change this I suggest you take some time to read the SQL Server documentation, specifically the secion about authentication.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic