cancel
Showing results for 
Search instead for 
Did you mean: 

How to Modify DB Records Using JDBC Connector FrameWork

Former Member
0 Kudos

Hi everyone,

I am using the JDBC Connector Framework to connect to an Oracle database. To retrieve data from the database I am currently using the INativeQuery which works fine for me.

That's how I'm using it.

INativeQuery query = connection.newNativeQuery();

ResultSet result = (ResultSet)query.execute(sqlString);

Although I can use the same syntax to insert, update or delete records in the database, this same syntax does not give me information about how many records were modified.

In the Connection API there is a method that uses the IExecution object:

IExcution e = connection.newExecution();

int updatedRecs = e.execute(IOperation);

Although the syntax seems to be straightforward, I don't know how to define the IOperation object.

Does anyone have any idea how to do it or retrieve the number of updated records in a different way?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

I tried to build more complex queries like

SELECT "EMP"."NAME", "EMP"."SURNAME", "DEPT"."DEP" 
FROM ( "EMP" ) INNER JOIN ( "DEPT" ) 
ON ( "EMP"."ID" = "DEPT"."EMPID" )

Unfortunately I figured out, BusinessObject information is not used to build to query. All <b>"EMP".</b> and <b>"DEPT".</b> are missing.

May be SAP did not finish the coding of the execute(IOperation).

I hope someone from SAP will have a brief look at this.

Have a nice day,

Henric

Former Member
0 Kudos

Hi,

I tried to code "select name, surname from emp" as IOperation but I got an exception. May be there is something still missing.

IOperation operation = new IQueryOperation() {

public ISelect getSelect() {
   return new ISelect() {
   public int getSymbolCount() {
      return 2;
   }
   public ISelectSymbol getSymbol(int index) {
      switch (index) {
         case 0 :
            return new ISelectSymbol() {
               public Class getType() {
                  return String.class;
               }
               public String getName() {
                  return "name";
               }
            };
         case 1 :
            return new ISelectSymbol() {
               public Class getType() {
                  return String.class;
               }
               public String getName() {
                  return "surname";
               }
            };
         default :
            return null;
      }
   }
   public Iterator getSymbols() {
      HashSet set = new HashSet();
      set.add(new ISelectSymbol() {
         public Class getType() {
            return String.class;
         }
         public String getName() {
            return "name";
         }
      });
      set.add(new ISelectSymbol() {
         public Class getType() {
            return String.class;
         }
         public String getName() {
            return "surname";
         }
      });
      return set.iterator();
   }
   public boolean isDistinct() {
      return false;
   }
   public boolean isStar() {
      return false;
   }
};
}

public IFrom getFrom() {
   return new IFrom() {
      public Iterator getClauses() {
         HashSet set = new HashSet();
         set.add(new IUnaryFromClause() {
            public IBusinessObjectSymbol getBusinessObject() {
               return new IBusinessObjectSymbol() {
                  public String getAlias() {
                     return "emp";
                  }
                  public String getName() {
                     return "emp";
                  }};
            }
         });
         return set.iterator();
      }
      public Iterator getBusinessObjects() {
         return null;
      }
   };
}

public ICriteria getCriteria() {
   return null;
}

public IOrderBy getOrderBy() {
   return null;
}

public IGroupBy getGroupBy() {
   return null;
}

public ICriteria getHaving() {
   return null;
}

public int getType() {
   return IOperation.QUERY_OPERATION;
}
};

Does a generator exist to build an IOperation imp.-class?

Regards,

Henric

Former Member
0 Kudos

Hi again,

I found some coding to check if the IOperation works properly:

import com.sapportals.connector.execution.objects.helper.QueryAssemblingException;
import com.sapportals.connector.execution.objects.language.IOperation;
import com.sapportals.jdbcconnector.execution.objects.JDBCAssembler;

public class TestJDBC {

	public static void main(String[] args) {
		IOperation operation = new Operation();
		JDBCAssembler assembler = new JDBCAssembler();
		try {
			String result = assembler.assemble(operation);
			System.out.println(result);
		} catch (QueryAssemblingException e) {
			e.printStackTrace();
		}		
	}
}

For select I use IAttributeSymbol.

See ya ...

Henric