从一个数据库到另一个数据库的数据

时间:2018-06-23 14:53:53

标签: java sql database

有必要将数据从一个数据库传输给朋友,我查看了网站上的其他主题,但它们没有帮助我。我这里有这样一个数据库。以此方式填充到程序中

create table users_flight(
id integer not null generated always AS identity PRIMARY KEY,
users_id integer not null references users(id)  ON DELETE CASCADE,
flights_id integer not null references flight(id)  ON DELETE CASCADE,
dates varchar (50) not null unique,
status boolean default false
);

INSERT into users_flight values(default,?,?,?,default);

然后,以这种方式选择元素

SELECT uf.id, u.f_name, u.l_name, ar.name, f.name, f.startPoint, f.endPoint, f.number, f.departure_date, uf.dates, uf.status FROM users u, flight f, aircompany ar, users_flight uf WHERE uf.users_id=u.id AND f.id=uf.flights_id AND f.aircompany_id=ar.id

结果是我在程序中得到了这个表: enter image description here

我希望单击按钮时,此数据被复制到另一个表。为此,我创建了一个这样的表,并尝试以这种方式填充它。

create table acceptUserFlight(
  id integer not null generated always as identity PRIMARY KEY,
  firstN varchar(50) not null,
  lastN varchar(50) not null,
  aircompanyN varchar(50),
  fName varchar(50) not null,
  fStartPoint varchar(100) not null,
  fEndPoint varchar(100) not null,
  fNumber integer not null,
  fDepartureDate date
);

INSERT INTO acceptUserFlight(firstN, lastN, aircompanyN, fName, fNumber, fStartPoint, fEndPoint, fDepartureDate)SELECT u.f_name, u.l_name, ar.name, f.name, f.number, f.startPoint, f.endPoint, f.departure_date FROM users u, flight f, aircompany ar, users_flight uf WHERE uf.id=? AND uf.users_id=u.id AND f.id=uf.flights_id AND f.aircompany_id=ar.id

但是,结果是,我仅获得列的名称。如何正确形成SQL查询?

0 个答案:

没有答案