Guest_imported
New member
- Jan 1, 1970
- 0
I've two simple tables:
create table table1(
name VARCHAR2(10),
ID INTEGER,
unique(name),
primary key(ID));
create table table2(
name VARCHAR2(10),
table1ID INTEGER,
primary key(name),
foreign key(table1ID) references table1);
In short, table2 has a foreign key referencing table1, very straight forward.
Let's say table1 has a record:
name id
---- --
abc 1
I'm writing JDBC methods for accessing these tables. The defined interface for inserting a new table2 value is:
AddTable2( String name, String table1ID);
In order to insert a new record into table2 referencing this record, I should write:-
insert into table2 (name, table1ID) ('whatever', 1);
and I can easily map 'abc' and the value 1 using a simple query.
However, the requirement states that in order to avoid unneccessary JDBC overhead, triggers are asked to do the mapping task.
So I tried writing a BEFORE INSERT trigger so that the sql statement
insert into table2 (name,table1ID) ('whatever', 'abc');
would still work. But before the trigger is invoked the statement is rejected by the dataype checking, cos I placed a string to a place where an integer should be.
Does anyone know if there's a work around for it? Or am I misreading the requirements?
I've been stuck on this for a long time, so I really appreciate any input.
Thanx again.
Andrew
create table table1(
name VARCHAR2(10),
ID INTEGER,
unique(name),
primary key(ID));
create table table2(
name VARCHAR2(10),
table1ID INTEGER,
primary key(name),
foreign key(table1ID) references table1);
In short, table2 has a foreign key referencing table1, very straight forward.
Let's say table1 has a record:
name id
---- --
abc 1
I'm writing JDBC methods for accessing these tables. The defined interface for inserting a new table2 value is:
AddTable2( String name, String table1ID);
In order to insert a new record into table2 referencing this record, I should write:-
insert into table2 (name, table1ID) ('whatever', 1);
and I can easily map 'abc' and the value 1 using a simple query.
However, the requirement states that in order to avoid unneccessary JDBC overhead, triggers are asked to do the mapping task.
So I tried writing a BEFORE INSERT trigger so that the sql statement
insert into table2 (name,table1ID) ('whatever', 'abc');
would still work. But before the trigger is invoked the statement is rejected by the dataype checking, cos I placed a string to a place where an integer should be.
Does anyone know if there's a work around for it? Or am I misreading the requirements?
I've been stuck on this for a long time, so I really appreciate any input.
Thanx again.
Andrew