Reputation: 103
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
Upvotes: 1
Views: 2383
Reputation: 547
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.
Upvotes: 0
Reputation: 18704
;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;
Upvotes: 2