为什么我从 Apache Derby 收到这些错误?

发布于 2024-12-17 09:53:56 字数 959 浏览 5 评论 0原文

我运行我的程序,连接数据库,然后它给我两个错误。一种说法

'Schema "ROOT" does not exist' 

和另一种说法

'Lexical error at line 1, column 8. Encountered: "@"(64), after:"".

下面是两个 SQL 语句的代码:

private void UpdateJTable() {
    String sql ="select idhonscores AS RowNo , Name, Characters, Kills, Deaths, Assists, XPM, CK from honscores";
    try {
        st = conn.prepareStatement(sql);
        rs = st.executeQuery();
        table.setModel(DbUtils.resultSetToTableModel(rs));

    } catch(Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }
}

That is from the first error and

String sql3 ="SELECT "+"@rn:=@rn+1"+" AS Rank, Name, Kills 
              FROM (Select Name, sum(Kills) as Kills 
                    from honscores group by Name order by Kills DESC) t1,
                   (SELECT "+"@rn:=0"+") t2;";

Is for the second error

I run my program, the database is connected to and then it gives me two errors. One saying

'Schema "ROOT" does not exist' 

and another saying

'Lexical error at line 1, column 8. Encountered: "@"(64), after:"".

Here is the code from the two SQL statements:

private void UpdateJTable() {
    String sql ="select idhonscores AS RowNo , Name, Characters, Kills, Deaths, Assists, XPM, CK from honscores";
    try {
        st = conn.prepareStatement(sql);
        rs = st.executeQuery();
        table.setModel(DbUtils.resultSetToTableModel(rs));

    } catch(Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }
}

That is from the first error and

String sql3 ="SELECT "+"@rn:=@rn+1"+" AS Rank, Name, Kills 
              FROM (Select Name, sum(Kills) as Kills 
                    from honscores group by Name order by Kills DESC) t1,
                   (SELECT "+"@rn:=0"+") t2;";

Is for the second error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧时光的容颜 2024-12-24 09:53:56
  1. 在 derby 中,默认架构始终是您用来创建 jdbc 连接的用户的架构。我无法从你的问题中看出你如何初始化和设置德比数据库。但是将 ;create=true 附加到 jdbc-url 可能会有所帮助(如果数据库和模式不存在,这将创建它)。

更改为不同的架构

SET SCHEMA MYSCHEMA;
  1. 您可以通过执行以下命令 语法可能在 derby 中不可用。并非所有在另一个数据库中工作的东西(特别是特定于数据库的)都可以在德比中工作。
  1. In derby the default schema is always the schema of the user you use to create the jdbc connection. I can't tell from you question, how you initialize and setup the derby database. But appending ;create=true to the jdbc-url might help (this will create the db and schema if it does not exist).

You can change to a different schema by executing:

SET SCHEMA MYSCHEMA;
  1. The @-syntax might not be available in derby. Not everything that works in another db (especially if it is db specific) will work in derby.
好倦 2024-12-24 09:53:56

关于用户名是默认模式的说法是正确的。如果您不指定用户名,则默认架构将为 APP。这个模式总是存在的。如果您以 root 用户身份连接,则在您在其中创建表之前不会创建模式“root”。例如:

ij> connect 'jdbc:derby:memory:foo;user=root;create=true';
ij> show schemas;
TABLE_SCHEM                   
------------------------------
APP                           
NULLID                        
SQLJ                          
SYS                           
SYSCAT                        
SYSCS_DIAG                    
SYSCS_UTIL                    
SYSFUN                        
SYSIBM                        
SYSPROC                       
SYSSTAT                       

11 rows selected
ij> create table foo(i int) ;
0 rows inserted/updated/deleted
ij> show schemas;
TABLE_SCHEM                   
------------------------------
APP                           
NULLID                        
ROOT                          
SQLJ                          
SYS                           
SYSCAT                        
SYSCS_DIAG                    
SYSCS_UTIL                    
SYSFUN                        
SYSIBM                        
SYSPROC                       
SYSSTAT                       

12 rows selected

Wrt。表名和列名中的@:仅当引用包含@的名称时才允许这样做。例如:

ij> create table @T@(@c@ int);
ERROR 42X02: Lexical error at line 1, column 14.  Encountered: "@" (64), after : "".
ij> create table "@T@"("@c@" int);
0 rows inserted/updated/deleted
ij> insert into "@T@" values (0),(1),(2);
3 rows inserted/updated/deleted
ij> select * from "@T@";
@c@        
-----------
0          
1          
2          

3 rows selected

但请注意,引用名称时区分大小写。因此,在前面的示例中,以下操作失败:

ij> select * from "@t@";
ERROR 42X05: Table/View '@t@' does not exist.

因为在引号中,@T@ 和 @t@ 被视为不同的名称。

What has been said about username being the default schema is true. If you do not specify a username the default schema will be APP. This schema always exists. If you connect as user root the schema "root" will not be created until you create a table in it. E.g:

ij> connect 'jdbc:derby:memory:foo;user=root;create=true';
ij> show schemas;
TABLE_SCHEM                   
------------------------------
APP                           
NULLID                        
SQLJ                          
SYS                           
SYSCAT                        
SYSCS_DIAG                    
SYSCS_UTIL                    
SYSFUN                        
SYSIBM                        
SYSPROC                       
SYSSTAT                       

11 rows selected
ij> create table foo(i int) ;
0 rows inserted/updated/deleted
ij> show schemas;
TABLE_SCHEM                   
------------------------------
APP                           
NULLID                        
ROOT                          
SQLJ                          
SYS                           
SYSCAT                        
SYSCS_DIAG                    
SYSCS_UTIL                    
SYSFUN                        
SYSIBM                        
SYSPROC                       
SYSSTAT                       

12 rows selected

Wrt. @ in table and column names: That is only allowed if you quote the name containing @. E.g.:

ij> create table @T@(@c@ int);
ERROR 42X02: Lexical error at line 1, column 14.  Encountered: "@" (64), after : "".
ij> create table "@T@"("@c@" int);
0 rows inserted/updated/deleted
ij> insert into "@T@" values (0),(1),(2);
3 rows inserted/updated/deleted
ij> select * from "@T@";
@c@        
-----------
0          
1          
2          

3 rows selected

Note however, that when quoting a name it becomes case-sensitive. So in the previous example the following fails:

ij> select * from "@t@";
ERROR 42X05: Table/View '@t@' does not exist.

because in quotes, @T@ and @t@ are considered different names.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文