在DERBY查询中省略模式

编程入门 行业动态 更新时间:2024-10-23 15:26:39
本文介绍了在DERBY查询中省略模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了一个名为movie_db的数据库,将默认模式设置为APP。 然后创建一个名为USERS的示例表。

我与数据库的连接如下:

< bean id =dataSourceclass =org.springframework.jdbc.datasource.DriverManagerDataSource> < property name =driverClassNamevalue =org.apache.derby.jdbc.ClientDriver/> < property name =urlvalue =jdbc:derby:// localhost:1527 / movie_db/> < property name =usernamevalue =root/> < property name =passwordvalue =pass/> < / bean>

现在我想写一些测试,并尝试执行以下查询:

SELECT * FROM USERS;

我得到了什么:

java.sql.SQLSyntaxErrorException:Table / View'USERS'不存在。

当我指定我正在使用的模式:

SELECT * FROM APP.USERS

如何在查询中省略模式名? strong> 像Bryan说的,我创建了一个名为我的默认模式的用户,并通过此登录进行授权。这是在查询中省略模式名称的最简单的方法。但是如果我想使用多个模式,唯一的方法是显式地设置模式。

解决方案

默认模式名称:

  • 在连接到数据库之后发出SET SCHEMA语句。
  • 如果您尚未发出SET SCHEMA语句,则Derby将使用您的用户名作为模式名称。

    因此,如果您以用户APP登录,并且不发出SET SCHEMA语句,名称将是APP。

    I have created a database named 'movie_db', set default schema to APP. Then created a sample table named 'USERS'.

    My connection to DB is as follows:

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"/> <property name="url" value="jdbc:derby://localhost:1527/movie_db"/> <property name="username" value="root"/> <property name="password" value="pass"/> </bean>

    Now I want to write some tests and try to execute the following query:

    SELECT * FROM USERS;

    What I get:

    java.sql.SQLSyntaxErrorException: Table/View 'USERS' does not exist.

    When I specify exactly the schema I'm using:

    SELECT * FROM APP.USERS

    everything works fine.

    How can I omit schema name in my query?

    UPDATE: Like Bryan said, I've created a user with the name of my default schema and authorize with this login. This is the most simple way to omit schema name in the query. But still if I want to use multiple schemas the only way is to set schema explicitly.

    解决方案

    There are basically two ways to control the default schema name:

  • Issue the SET SCHEMA statement after you have connected to the database.
  • Login as the user with the same name as the schema you wish to use.
  • If you haven't issued a SET SCHEMA statement, then Derby will use your username as the schema name.

    So if you login as user "APP", and don't issue a SET SCHEMA statement, then your schema name will be APP.

    更多推荐

    在DERBY查询中省略模式

    本文发布于:2023-11-03 14:59:16,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1555416.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:模式   DERBY

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!