开发者

JDBC url with database containing spaces

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 = DriverMa开发者_StackOverflownager.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.


Does this work?

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


You should use the following syntax:

jdbc:sqlserver://"your Server Name":1433;DataBaseName="Data Base Name"

Example:

jdbc:sqlserver://localhost:1433;DataBaseName=testDB
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜