开发者

JDBC Change Default Schema

开发者 https://www.devze.com 2023-01-15 21:50 出处:网络
I\'m trying to connect to a sql server 2005 database via JDBC. I get the error: com.microsoft.sqlserver.jdbc.SQLServerException: The SELECT permission

I'm trying to connect to a sql server 2005 database via JDBC.

I get the error:

com.microsoft.sqlserver.jdbc.SQLServerException: The SELECT permission was denied on the object 'MyTable', database 'MyDatabase', schema 'dbo'.

The schema I use to connect is "MyUser". How do I connect us开发者_Go百科ing MyUser as opposed to dbo?

Thanks!


To clear things up: You connect to SQL Server using a user, not a schema. You don't say what version of SQL Server you're connecting to, but it used to be the case that the two were equivalent. As of 2005+, that is no longer true.

dbo is the default schema (think of it as a namespace); what the error message is telling you is the user you are connecting with (If I understand correctly, that's MyUser) does not have permission to SELECT from the MyTable table, which is part of the dbo schema in the MyDatabase database.

The first thing to do is confirm whether or not the user you're connecting with does or does not have SELECT permissions on that table. The second thing to do is, if it doesn't, either give MyUser that permission or use a different user to perform the SELECT statement.


i found that you have to specify your schema in your POJOS definitions.

In my case I got the same trouble using JPA (Entities / Annotations) and I realized that specifing the schema property in the @Table annotation works.

for example:

@Table(name = "address", **schema="*dbo*"**, catalog = "petcatalog")

I hope this helps you.

0

精彩评论

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