简体   繁体   English

JDBC更改默认架构

[英]JDBC Change Default Schema

I'm trying to connect to a sql server 2005 database via JDBC. 我正在尝试通过JDBC连接到sql server 2005数据库。

I get the error: 我得到错误:

com.microsoft.sqlserver.jdbc.SQLServerException: The SELECT permission was denied on the object 'MyTable', database 'MyDatabase', schema 'dbo'. com.microsoft.sqlserver.jdbc.SQLServerException:对对象“ MyTable”,数据库“ MyDatabase”,架构“ dbo”的SELECT权限被拒绝。

The schema I use to connect is "MyUser". 我用来连接的架构是“ MyUser”。 How do I connect using MyUser as opposed to dbo? 如何使用MyUser而不是dbo进行连接?

Thanks! 谢谢!

To clear things up: You connect to SQL Server using a user , not a schema . 要清除问题:您使用user而不是schema连接到SQL Server。 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. 您没有说要连接到哪个版本的SQL Server,但是过去这两个版本是等效的。 As of 2005+, that is no longer true . 从2005年起, 这种说法不再成立

dbo is the default schema (think of it as a namespace); dbo是默认模式(将其视为名称空间); 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. 什么错误信息,告诉你的就是你与连接用户 (如果我理解正确的话,这是MYUSER)没有权限来SELECTMyTable表,这是 MyDatabase的数据库中的dbo架构的一部分

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. 首先要做的是确认与之连接的用户是否对该表具有SELECT权限。 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. 第二件事要做的是,如果没有,请给MyUser那个权限,或使用其他用户执行SELECT语句。

i found that you have to specify your schema in your POJOS definitions. 我发现您必须在POJOS定义中指定架构。

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. 以我为例,使用JPA(实体/注释)遇到了同样的麻烦,并且我意识到在@Table注释中指定schema属性是@Table

for example: 例如:

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

I hope this helps you. 我希望这可以帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM