MsSQL forbindelse i Java
HejJeg skal have lavet en forbindelse til MsSQL i Java. Jeg bruger følgende stykke kode til at connecte til min db. problemet er at jeg får en fejl:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user 'user'. Reason: Not associated with a trusted SQL Server connection.
Er der nogen der kan hjælpe mig??
import java.*;
public class Connect{
private java.sql.Connection con = null;
private String url = "jdbc:microsoft:sqlserver://";
private String serverName= "localhost";
private String portNumber = "1433";
private String databaseName= "databasename";
private String userName = "user";
private String password = "pass";
public Connect(){}
private String getConnectionUrl(){
return url+serverName+":"+portNumber+";databaseName="+databaseName+";";
}
private java.sql.Connection getConnection(){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
if(con!=null) System.out.println("Connection Successful!");
}catch(Exception e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}
return con;
}
}