Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • 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.util.*;
import java.lang.reflect.*;

import*; //Include the WebSphere MQ classes for Java package

public class MQSample {

// code identifier
public static final String sccsid = "@(#) javabase/samples/, 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");, host);, port);, 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 ( ex) {
System.out.println("An IOException occured whilst writing to the message buffer: "
+ ex);
Thanks for help in advance.
Lasse Koskela
Posts: 11962
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to IBM/WebSphere...
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!