aspose file tools*
The moose likes JDBC and the fly likes Why this Program throws SQLException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Why this Program throws SQLException" Watch "Why this Program throws SQLException" New topic
Author

Why this Program throws SQLException

swarupa patil
Ranch Hand

Joined: Feb 22, 2006
Posts: 62
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

Joined: Apr 14, 2004
Posts: 10336


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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
swarupa patil
Ranch Hand

Joined: Feb 22, 2006
Posts: 62
I didnot understand ur meaning of
SQL server authentication and windows authentication
Where from we get these both.
Please reply ASAP
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why this Program throws SQLException
 
Similar Threads
JDBC with MS SQL 2000
BeanInstantiationException
MS Sql server2000 connection problem
JDBC Connection??
HELP please with SQL Server