?
Solved

SQL Server 2000 Driver for JDBC errors

Posted on 2003-03-18
12
Medium Priority
?
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 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