I am trying to write a java program that will need to loop through a list of "old values" to get the list of "new values" from an oracle database table. list of OLD values, I would like to pass this list from a shell script, which will be a wrapper for the java program.
a b c
--select statement something like
select new_name from items where old_name = ? //loop through the list of old values
the second step will be to use new_name from above query to use in the below select statement
select msgid from new_name
i am trying to do something like this -
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@//host:port/SID", "userid", "password");
Statement stmt = conn.createStatement();
for (int i=0; i < arg.length; i++)
{
ResultSet getNewVal = stmt.executeQuery("select new_name from items where old_name = " + old_name[i]);
while (getNewVal.next()){
String newVal = getNewVal.getString(1);
ResultSet getMsgID = stmt.executeQuery("select msgid from " + newVal );
System.out.println (getMsgID.getString(1));
}
}
Issue - ResultSet from first query gets closed and generates an exception as I execute the second query (Closed Resultset: next)
any suggestion?
As requested including example table definition.
create table items ( new_name varchar2(20),old_name varchar2(20) );
create table new_name ( msgid varchar2(20));