views:

12

answers:

1

I'm trying to connect to a SQL Server database using JDBC, the database I'm trying to connecto to contains a space, and unfortunately I have no control over the name, so I can't change it.

The code I'm using is:

String jdbcString = "jdbc:sqlserver://" + hostname + ":" + port + ";databaseName=Database Name";
    try {
        connection = DriverManager.getConnection(jdbcString, username, password);
    }

I've also tried following the instructions on this link: http://msdn.microsoft.com/en-us/library/ms378428%28SQL.90%29.aspx by haveing the space inside braces:

String jdbcString = "jdbc:sqlserver://" + hostname + ":" + port + ";databaseName=Database{ }Name";

but that doesn't seem to work either.

The error message I gee is:

ERROR: Couldn't connect to the database: The connection string contains a badly formed name or value.

I'm using the latest JDBC driver from Microsoft.

+1  A: 

Does this work?

String jdbcString = "jdbc:sqlserver://" + hostname + ":" + port + ";databaseName={Database Name}";
Tarski
That did work! I can't believe I didn't try that :) Thanks a lot!
Izbitzer