0

Microsoft SQL Server 2008 R2.

Created login user.

Default database is set to 'master'.

Created a database named 'slave'.

Use JDBC URL jdbc:sqlserver://localhost:1433;databaseName=slave

All operations performed with this URL are going to the 'master' database not 'slave'.

Is there a reason this URL is not overriding the default database? Is it based on the User Mapping?

Ashot Karakhanyan
  • 2,804
  • 3
  • 23
  • 28

1 Answers1

0

Here is a connection code : - see any differences ?
- for me it works well

public void connectDB()
{
    try
    {
        String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=DBNAME;user=user;password=pass";
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        Connection con = DriverManager.getConnection(connectionUrl);
        System.out.println("Database connection = "+con );
    }
    catch( Exception e )
    {
        e.printStackTrace();
        System.out.println( "Error connecting to database.  Error: "+e.getMessage() );
    }

}
Up_One
  • 5,213
  • 3
  • 33
  • 65