?
Solved

SQL Server 2000 Driver for JDBC errors

Posted on 2003-03-18
12
Medium Priority
?
225 Views
Last Modified: 2012-05-05
I have recentlyinstalled the SQL Server 2000 Driver for JDBC on my local machine. I have SQLServer 2000 on my local machine, and I am trying to access a database using the driver but I keep getting errors. This is the simple code I am using:


import java.sql.*;
import java.util.*;
import com.microsoft.jdbc.sqlserver.SQLServerDriver ;

public class sql2000test {
   
    public static void main(String[] args){
        try{
       
           Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost;database=TestSQL");
            Statement myStmt = conn.createStatement();
           ResultSet myRs = myStmt.executeQuery("SELECT * FROM MyTable");

            while (myRs.next()){
                System.out.println("hi");
            }  
            conn.close();
        }catch (SQLException exc){
            System.out.println(exc);
        }catch (ClassNotFoundException exc){
            System.out.println(exc);
        }
       
    }
}

When using the DBURL "jdbc:microsoft:sqlserver://localhost;database=TestSQL" I get the following error:

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


And when I specify the name of my machine in the DBURL instead of using localhost I get the following error:

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.

What is likely to be the problem here? Do I have to modify my SQLSERVER2000 configuration? How do you find out what port SQLSERVER 2000 is on on your local machine?
0
Comment
Question by:Den1se
  • 8
  • 3
12 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 8158514
Connection conn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost;database=TestSQL", "USERNAME", "PASSWORD" );
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8158532
And, to be completely safe:

 Connection conn = null ;
 Statement  myStmt = null ;
 ResultSet myRs = null ;
 try{
   Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
   conn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost;database=TestSQL", "USERNAME", "PASSWORD" );
   myStmt = conn.createStatement();
   myRs = myStmt.executeQuery("SELECT * FROM MyTable");

   while (myRs.next()){
     System.out.println("hi");
   }  
   myRs.close() ;
   myRs = null ;
   myStmt.close() ;
   myStmt = null ;
   conn.close() ;
   conn = null;
 }catch (SQLException exc){
   System.out.println(exc);
 }catch (ClassNotFoundException exc){
   System.out.println(exc);
 }
 finally {
    try
    {
      if (myRs != null)
      {
        myRs.close();
      }
    }
    catch(SQLException e)
    {
    }
    try
    {
      if (myStmt != null)
      {
        myStmt.close();
      }
    }
    catch(SQLException e)
    {
    }
    try
    {
      if (conn != null)
      {
        conn.close();
      }
    }
    catch(SQLException e)
    {
    }
 }
0
 

Author Comment

by:Den1se
ID: 8158567
When I add a user and password e.g.

"jdbc:microsoft:sqlserver://localhost;database=TestSQL;user=newUser;password=password"

I get the following error message:

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


I have set up newUser as a user of the database.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Den1se
ID: 8158593
I have made the modifications you suggest and still get the error:

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user 'newUser'. Reason: Not associated with a trusted SQL Server connection.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8158663
Have a look here...  you need to set up your sql server to accept you over a trusted connection :-)

http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20313428.html
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8158670
oooh...hang on...that link was rubbish...I'll have another look :-)
0
 

Author Comment

by:Den1se
ID: 8158685
Solved it, I didn't have SQLServer set up for mixed authentication. It works now, cheers anyway.
0
 
LVL 35

Accepted Solution

by:
TimYates earned 200 total points
ID: 8158687
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8158690
Hehehe...you beat me by one minute ;-)

Curse my slow fingers ;-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8158699
> Solved it, I didn't have SQLServer set up for mixed authentication. It works now, cheers anyway.

Ahhh, but don't forget that I helped solve your original problem, where you weren't passing the username and password to the server ;-)

Hee hee!

Cool!

Good luck with it!!

:-)

Tim
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8159204
Did my answer help your original question Den1se?

If so, could you accept one of my comments as an answer, so that this question can be moved into the PAQ section of this site.

Thanks :-)
0
 

Expert Comment

by:CleanupPing
ID: 9058622
Den1se:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Don’ts and Dos are two important end products of software testing basics that a tester needs to regard. This article attempts to explain the principles of both.
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question