Search code examples
javasqldatabaseeclipsederby

Why am I getting these errors from Apache Derby?


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


Solution

    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.