lundi 26 janvier 2015

As I'm beginner I'm trying to use this query to insert foreign key elements in java... this query is working in phpMyAdmin but not working in java


CREATE TABLE foo ( id BIGSERIAL NOT NULL UNIQUE PRIMARY KEY, type VARCHAR(60) NOT NULL UNIQUE );


CREATE TABLE bar (



id BIGSERIAL NOT NULL UNIQUE PRIMARY KEY,
description VARCHAR(40) NOT NULL UNIQUE,
foo_id BIGINT NOT NULL REFERENCES foo ON DELETE RESTRICT


);


Say the first table foo is populated like this:


INSERT INTO foo (type) VALUES



( 'red' ),
( 'green' ),
( 'blue' );


can I have the query which can work in java actually the below query is working while inserting in php my admin but in java it is not working ... please help me to write this query in java INSERT INTO bar (description, foo_id) VALUES ( 'testing', (SELECT id from foo WHERE type='blue') ), ( 'another row', (SELECT id from foo WHERE type='red' ) );





Aucun commentaire:

Enregistrer un commentaire