• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

MQWebsphere(MQJE001: An MQException occurred: Completion Code 2, Reason 2059)

Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i trying to run MQSample class with MQ Websphere on windows xp.But i got Exception
MQJE001: An MQException occurred: Completion Code 2, Reason 2059

My Approch to run MQSample class is as follows

Step 1-:First i open dos panel and i run mq Queue manager by using following commands
it gives message as follows

Starting MQSC for queue manager QM_sw12.

Step 2-: I start another dos panel and run program MQSample but it gives exception message as follows

Connecting to queue manager: QM_sw12
MQJE001: An MQException occurred: Completion Code 2, Reason 2059
MQJE011: Socket connection attempt refused
MQJE001: An MQException occurred: Completion Code 2, Reason 2059
MQJE011: Socket connection attempt refused
A WebSphere MQ Error occured : Completion Code 2 Reason Code 2059

i have set all environment variables and i have also tested MQIVP class using same approch as shown above and it is working fine.

My MQSample code is-:

import java.text.*;
import java.io.*;
import java.util.*;
import java.lang.reflect.*;

import com.ibm.mq.*; //Include the WebSphere MQ classes for Java package
import com.ibm.mq.MQException;

public class MQSample {

// code identifier
public static final String sccsid = "@(#) javabase/samples/MQSample.java, java, j000, j000-L050412 1.10 05/04/06 16:40:38";

// define the name of the QueueManager
private static final String qManager = "QM_sw12";
// and define the name of the Queue
private static final String qName = "SYSTEM.DEFAULT.LOCAL.QUEUE";
Properties properties = new Properties(); // Contains system settings.
// main method: simply call the runSample() method
public static void main(String args[]) {
new MQSample().runSample();

public void runSample() {


// Load system properties from file
FileInputStream fis = new FileInputStream("properties.ini");

// List system properties

ByteArrayOutputStream baos = new ByteArrayOutputStream();
properties.list(new PrintStream(baos));

// Prepare MQ Series environment
String chl = properties.getProperty("CHANNEL_NAME");
String host = properties.getProperty("HOST_NAME");
String port = properties.getProperty("PORT");
String qmgr = properties.getProperty("QUEUE_MANAGER");

MQEnvironment.properties.put(MQC.HOST_NAME_PROPERTY, host);

MQEnvironment.properties.put(MQC.PORT_PROPERTY, port);

MQEnvironment.properties.put(MQC.CHANNEL_PROPERTY, chl);
PrintStream out1 = new PrintStream(
new BufferedOutputStream (
new FileOutputStream("mqtrace.out")));

MQEnvironment.enableTracing(5, out1);

catch (Exception e)

try {

// Create a connection to the QueueManager
System.out.println("Connecting to queue manager: "+qManager);
MQQueueManager qMgr = new MQQueueManager(qManager);

// Set up the options on the queue we wish to open

// Now specify the queue that we wish to open and the open options
System.out.println("Accessing queue: "+qName);
MQQueue queue = qMgr.accessQueue(qName, openOptions);

// Define a simple WebSphere MQ Message ...
MQMessage msg = new MQMessage();
// ... and write some text in UTF8 format
msg.writeUTF("Hello, World!");

// Specify the default put message options
MQPutMessageOptions pmo = new MQPutMessageOptions();

// Put the message to the queue
System.out.println("Sending a message...");
queue.put(msg, pmo);

// Now get the message back again. First define a WebSphere MQ message
// to receive the data
MQMessage rcvMessage = new MQMessage();

// Specify default get message options
MQGetMessageOptions gmo = new MQGetMessageOptions();

// Get the message off the queue.
System.out.println("...and getting the message back again");
queue.get(rcvMessage, gmo);

// And display the message text...
String msgText = rcvMessage.readUTF();
System.out.println("The message is: " + msgText);

// Close the queue
System.out.println("Closing the queue");

// Disconnect from the QueueManager
System.out.println("Disconnecting from the Queue Manager");
catch (MQException ex) {
System.out.println("A WebSphere MQ Error occured : Completion Code "
+ ex.completionCode + " Reason Code " + ex.reasonCode);
catch (java.io.IOException ex) {
System.out.println("An IOException occured whilst writing to the message buffer: "
+ ex);
Thanks for help in advance.
Posts: 11962
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to IBM/WebSphere...
and POOF! You're gone! But look, this tiny ad is still here:
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic