• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

HELP please with SQL Server

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
WHen I run as an Java apllication I get an error messsage in DriverManager.registerDriver(new com.microsoft.sqlserver.SQLServerDriver());

the error is : com.microsoft cannot be resolved or is not a type

and When I change to DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver()); runs but says No Suitable Driver

My code is this one to test my connection:
import java.sql.*;
public class TestarConnect{

public static void main(String [] args){

Connection conn;

try{

//DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());

DriverManager.registerDriver(new com.microsoft.sqlserver.SQLServerDriver());
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://ANDROMEDA;DATABASE=sac","eloi.teixeira","eloi197525");
System.out.println("Connection Successfull");

}
//catch(java.lang.ClassNotFoundException e , SQLException sqle) {

catch(SQLException e) {

//System.err.print("ClassNotFoundException: ");

System.err.println(e.getMessage());
System.out.println("SQLState: " + e.getSQLState());
System.out.println("VendorError: " + e.getErrorCode());
System.out.println("Connection unSuccessfull");

}
}


Thank you
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campos,
From the code you have posted, you are missing the following "import":

Good Luck,
Avi.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like com.microsoft.sqlserver.SQLServerDriver isn't in your classpath. Check it is.

(BTW: If you are trying to use the current MS JDBC driver for SQL Server, it is in the package structure: com.microsoft.jdbc.sqlserver.SQLServerDriver)
 
campos teixeira
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I changed the code because I am trying to test the connection but orinally I will connect through JSp.
this is the code:
import java.sql.*;

public class TestarConnect{

Connection conn;

public static void main(String [] args) throws ClassNotFoundException {

String uname = "Username";
String pwd = "password";
String url = "jdbc:microsoft:sqlserver://server:1433";

try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
DriverManager.getConnection(url,uname,pwd);
System.out.println("Connection Successfull");

}
catch(SQLException e){
System.err.println(e.getMessage());
System.out.println("VendorError: " + e.getErrorCode());
System.out.println("Connection failed");
}
}

}
And I am getting this error now:
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user 'eloi.teixeira'.

I am using MS SQL Server 2000 with windows 2000 and I alredy ask the dba to change to mixe mode authentication but nothing Can anyone see what is wrong with this code.

I am using eclipse and I am new with it but I added the msssqlserver.jar in the classpath of the eclipse and in the window like:
c:\Arquivos de Programas\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Arquivos de Programas\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;C:\Arquivos de Programas\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;

Thank you
 
campos teixeira
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used the import com.microsoft.sqlserver.SQLServerDriver; statement but I get the error message

The import com.microsoft.sqlserver.SQLServerDriver; cannot be resolved

What is that means I can see in the eclipse mssqlserver.jar package the com.microsoft.sqlserver.SQLServerDriver and the class SQLServerDriver ;

So what now?
 
campos teixeira
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul said :
It looks like com.microsoft.sqlserver.SQLServerDriver isn't in your classpath. Check it is.

(BTW: If you are trying to use the current MS JDBC driver for SQL Server, it is in the package structure: com.microsoft.jdbc.sqlserver.SQLServerDriver)

What mens to put "com.microsoft.sqlserver.SQLServerDriver isn't in your classpath." Are you saying that I have to put in windows environment in the classpath??

Can you explain it please??
 
campos teixeira
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did the import com.microsoft.jdbc.sqlserver.*; but says that The import com.microsoft.jdbc.sqlserver.*; is never used??
So doesnt compile?
 
campos teixeira
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well guys I got it!!
It looks like that it was the SQL Server Authentication mode I change to mixe mode and made a connection!

Thank you all
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic