Hi,
The following is the exception.
----------------------------------------------
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for
JDBC]Unable to conn
ect. Invalid URL.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source
)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at UBDAO.main(UBDAO.java:41)
Error Trace in getConnection() : [Microsoft][SQLServer 2000 Driver for JDBC]Unab
le to connect. Invalid URL.
------------------------------------------------------------------------
The problem is with the syntax where I am giving the database name. There's no problem with the authentication to the database since the same database, username and password is working fine if I pass the paramenter as a
string to this getConnection() method as follows.
---------------------------------------------
import java.io.*;
import java.sql.*;
public class UBDAO {
private java.sql.Connection con = null;
private final String url = "jdbc:microsoft:sqlserver://";
private final String serverName= "localhost";
private final String portNumber = "1433";
private final String databaseName= "CC";
private final String userName = "CC";
private final String password = "CC";
private String getConnectionUrl()
{
return url+serverName+":"+portNumber+";databaseName="+databaseName+";";
}
public static void main(String args[])
{
UBDAO ub = new UBDAO();
Connection con = null;
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = java.sql.DriverManager.getConnection(ub.getConnectionUrl(),ub.userName,ub.password);
if(con!=null) System.out.println("Connection Successful!");
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}
}
}
-----------------------------------------------------------
Thanks
JEAN
[ May 22, 2006: Message edited by: Jean Fore ]