ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » not able insert data into database using javacompute node

Post new topic  Reply to topic
 not able insert data into database using javacompute node « View previous topic :: View next topic » 
Author Message
anilmekala
PostPosted: Thu May 09, 2013 4:56 am    Post subject: not able insert data into database using javacompute node Reply with quote

Acolyte

Joined: 19 Oct 2012
Posts: 63

Hi All,

I am trying to insert data using java compute node by using ODBC in WMB 8.0. I am getting exception <com.ibm.broker.plugin.MbRecoverableException class:JNI method:Parser::passthruStatement source:BIPmsgs key:2401 >
and i traversed to exception list tracetext "Expected )" only this am getting. Please find my java code as below :

Code:
import com.ibm.broker.javacompute.MbJavaComputeNode;
import com.ibm.broker.plugin.MbElement;
import com.ibm.broker.plugin.MbOutputTerminal;
import com.ibm.broker.plugin.MbMessage;
import com.ibm.broker.plugin.MbMessageAssembly;
import com.ibm.broker.plugin.MbException;
import com.ibm.broker.plugin.MbSQLStatement;


public class SAMPLE_JAVACOMPUTE_INSERT_JavaCompute extends MbJavaComputeNode {

   public void evaluate(MbMessageAssembly assembly) throws MbException {
      MbOutputTerminal out = getOutputTerminal("out");      
      MbMessage message = assembly.getMessage();
      MbMessage newMsg= new MbMessage(message);
      MbMessageAssembly newAssembly = new MbMessageAssembly(assembly, newMsg);
      try
      {
         MbElement root = newMsg.getRootElement();         
         MbElement body = root.getLastChild();         
         MbElement emp = body.getFirstChild();         
         MbElement empid = emp.getFirstChild();
         MbElement empname = empid.getNextSibling();
         MbElement empdept = empname.getNextSibling();
         int emp_id = Integer.parseInt(empid.getValue().toString());
         String emp_name = empname.getValue().toString();
         String emp_dept = empdept.getValue().toString();         
         String error ="error in connection";

         MbSQLStatement state =createSQLStatement("SAMPLE",
               "PASSTHRU('INSERT INTO ADMINISTRATOR.EMPLOYEE(EMP_ID,EMP_NAME,EMP_DEPT) VALUES(?,?,?)',"+emp_id+","+emp_name+","+emp_dept+");", MbSQLStatement.SQL_TRANSACTION_COMMIT);
         
         state.setThrowExceptionOnDatabaseError(false);
         state.setTreatWarningsAsErrors(true);
         state.select(assembly, newAssembly);
         int sqlCode = state.getSQLCode();
         
         if(sqlCode!=0){
            
            newMsg.getRootElement().createElementAsFirstChild(0x1000000,"result",error);
         }
         
            

      out.propagate(assembly);
      }catch(Exception e){
         e.getMessage();
      }
      
      finally{}
   }

}


Please help me how to resolve above exception.

does any one has sample please share to me.

Thanks in advance.
Back to top
View user's profile Send private message
anilmekala
PostPosted: Thu May 09, 2013 5:31 am    Post subject: Reply with quote

Acolyte

Joined: 19 Oct 2012
Posts: 63

Hi,

I modify my createStatement as below :

MbSQLStatement state =createSQLStatement("SAMPLE",
"PASSTHRU('INSERT INTO ADMINISTRATOR.EMPLOYEE(EMP_ID,EMP_NAME,EMP_DEPT) VALUES(?,?,?)',"+emp_id+","+emp_name+","+emp_dept+");",
MbSQLStatement.SQL_TRANSACTION_COMMIT);

now am getting below exception:

First path element must be a valid correlation name
Back to top
View user's profile Send private message
Esa
PostPosted: Fri May 10, 2013 1:01 am    Post subject: Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

The path elements must be correlation names, not string values like "+emp_id+" in your example. Neither can they be names referring to variables in your java code. You are calling ESQL PASSTHRU function from your java code, and the attributes must be in correlation names that can be understood by ESQL.

Like "Environment.Variables.Foo" or "InputBody.Message.Field".
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri May 10, 2013 5:24 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

I think you're reading the quotes wrong, Esa.

I believe the code is attempting to insert the *value* of emp_id and etc, by using string concatenation.
Back to top
View user's profile Send private message
Esa
PostPosted: Fri May 10, 2013 6:38 am    Post subject: Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

mqjeff wrote:
I think you're reading the quotes wrong, Esa.

I believe the code is attempting to insert the *value* of emp_id and etc, by using string concatenation.


Yes, you are right.

So there is a slight possiblity that the code actually might work. In the case that by concatenating the values of those three fields you get something that ESQL may see as three valid correlation names separated by commas
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri May 10, 2013 7:28 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Esa wrote:
mqjeff wrote:
I think you're reading the quotes wrong, Esa.

I believe the code is attempting to insert the *value* of emp_id and etc, by using string concatenation.


Yes, you are right.

So there is a slight possiblity that the code actually might work. In the case that by concatenating the values of those three fields you get something that ESQL may see as three valid correlation names separated by commas


To be more clear, the point is that the result of the string concatenation should be a valid ESQL passthru statement.

The easiest way to debug this is to create the result of the string concatenation separately, and then pass that to the MbSQLStatement constructor.
Back to top
View user's profile Send private message
McueMart
PostPosted: Fri May 10, 2013 7:41 am    Post subject: Reply with quote

Chevalier

Joined: 29 Nov 2011
Posts: 490
Location: UK...somewhere

Code:

MbSQLStatement state =createSQLStatement("SAMPLE",
"PASSTHRU('INSERT INTO ADMINISTRATOR.EMPLOYEE(EMP_ID,EMP_NAME,EMP_DEPT) VALUES('"+emp_id+"','"+emp_name+"','"+emp_dept+"');",
MbSQLStatement.SQL_TRANSACTION_COMMIT);


Does that work?
Back to top
View user's profile Send private message
Esa
PostPosted: Sun May 12, 2013 12:14 pm    Post subject: Reply with quote

Grand Master

Joined: 22 May 2008
Posts: 1387
Location: Finland

Maybe something like this?

Code:

MbElement ref = contact admin.getGlobalEnvironment().getRootElement();
ref.createElementAsLastChild(MbElement.TYPE_NAMEVALUE, "emp_id", empid.getValue());
ref.createElementAsLastChild(MbElement.TYPE_NAMEVALUE, "emp_name", empid.getValue(), empname.getValue().toString());
ref.createElementAsLastChild(MbElement.TYPE_NAMEVALUE, "emp_dept", empid.getValue(), empdept.getValue().toString());

MbSQLStatement state =createSQLStatement("SAMPLE",
"PASSTHRU('INSERT INTO ADMINISTRATOR.EMPLOYEE(EMP_ID,EMP_NAME,EMP_DEPT) VALUES(?,?,?)', Environment.emp_id, Environment.emp_name, Environment.emp_dept)", MbSQLStatement.SQL_TRANSACTION_COMMIT);
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » not able insert data into database using javacompute node
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.