This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes HELP please with SQL Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "HELP please with SQL Server " Watch "HELP please with SQL Server " New topic
Author

HELP please with SQL Server

campos teixeira
Ranch Hand

Joined: May 23, 2004
Posts: 51
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
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

Campos,
From the code you have posted, you are missing the following "import":

Good Luck,
Avi.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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)


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
campos teixeira
Ranch Hand

Joined: May 23, 2004
Posts: 51
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

Joined: May 23, 2004
Posts: 51
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

Joined: May 23, 2004
Posts: 51
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

Joined: May 23, 2004
Posts: 51
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

Joined: May 23, 2004
Posts: 51
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
 
wood burning stoves
 
subject: HELP please with SQL Server
 
Similar Threads
JDBC Connection (or "I Am At My Wits End")
Could not locate DB driver
JDBC That fails in one workspace but works in another
SQLException while registrering driver
Connection with database Help