1

我正在尝试在我的学校项目中使用 Derby,但我遇到了一些问题。我的数据库名为 TheaterDB、derby 10.2.1、JDBC 3.0.0

我通过 java 发出的每个 SQL 请求都没有成功……我不明白为什么。例如,请求: SELECT * FROM User返回异常:

java.sql.SQLSyntaxErrorException: Schema 'ADMIN' does not exist

另一个不起作用的 SQL:

ALTER table theaterDB."Projection" ADD INDEX(fk_Projection_Movie(Movie_id));

Syntax error: Encountered "" at line 1, column 45.

这是java:

public Connection getConnection()
    {
        try
        {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
            System.out.println("Connection to: jdbc:derby:C:\\Users\\acouty\\theaterDB;create=true");
            // DriverManager.get
            return DriverManager.getConnection("jdbc:derby:C:\\Users\\acouty\\theaterDB;create=true", "admin", "");
        }
        catch (final Exception e)
        {
            e.printStackTrace();
            return null;
        }
    }
public List<User> listUsers()
    {
        final ArrayList<User> users = new ArrayList<User>();
        System.out.println("List user request");
        try
        {
            final Connection connection = getConnection();
            final String query = "SELECT * FROM User";
            System.out.println("query is : " + query);
            final ResultSet rs = connection.createStatement().executeQuery(query);
            while (rs.next())
            {
                System.out.println("salut");
            }
            return null;
        }
        catch (final Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

这是 .sql :

CREATE TABLE theaterDB."Users" 
(
    id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
    name VARCHAR(45) NOT NULL,
    lastname VARCHAR(45) NOT NULL ,
    email VARCHAR(45) NOT NULL ,
    adress VARCHAR(45) NOT NULL ,
    city VARCHAR(45) NOT NULL ,
    zip VARCHAR(45) NOT NULL ,
    login VARCHAR(45) NOT NULL ,
    password VARCHAR(45) NOT NULL ,
    admin SMALLINT NOT NULL DEFAULT 0,
    PRIMARY KEY (id)
);

CREATE  TABLE theaterDB."Movie"
(
  id INT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
  title VARCHAR(45) NOT NULL ,
  resume VARCHAR(500) ,
  genre VARCHAR(60)  ,
  grade INT  ,
  review_pub VARCHAR(200) ,
  review_gen VARCHAR(200)  ,
  poster VARCHAR(100)  ,
  duration INT  ,
  release_date VARCHAR(45)  ,
  PRIMARY KEY (id) 
);

CREATE  TABLE theaterDB."Projection" (
  id INT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
  date DATE ,
  length INT ,
  Movie_id INT NOT NULL ,
  price DECIMAL(10,0) ,
  location VARCHAR(45) NOT NULL ,
  place_nbr INT NOT NULL ,
  PRIMARY KEY (id)
);

ALTER TABLE theaterDB."Projection" 
    ADD FOREIGN KEY(Movie_id) 
    REFERENCES theaterDB."Movie" (id) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION;

CREATE TABLE  theaterDB."command" 
(
  id INT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
  Projection_id INT NOT NULL ,
  User_id INT NOT NULL ,
  paid SMALLINT NOT NULL ,
  PRIMARY KEY (id)
 );

 ALTER TABLE theaterDB."command" 
    ADD FOREIGN KEY(Projection_id) 
    REFERENCES theaterDB."Projection" (id) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION;

 ALTER TABLE theaterDB."command" 
    ADD FOREIGN KEY(User_id) 
    REFERENCES theaterDB."Users" (id) 
    ON DELETE NO ACTION 
    ON UPDATE NO ACTION;

谢谢

4

1 回答 1

0

我必须将 executeQuery 更改为执行,并将用户更改为“THEATERDB”。“USERS”


以下是工作要求:

SELECT * FROM "THEATERDB"."Users"


insert into "THEATERDB"."Users"(NAME, LASTNAME, EMAIL, ADRESS, CITY, ZIP, LOGIN, PASSWORD, ADMIN) values ('salut', 'salut', 'salut', 'salut', 'salut', 'salut', 'salut', 'salut', 1)

谢谢你的帮助:)。

于 2013-10-11T10:42:51.120 回答