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 » SQL Query Error in WMB

Post new topic  Reply to topic
 SQL Query Error in WMB « View previous topic :: View next topic » 
Author Message
SDS
PostPosted: Wed Feb 29, 2012 2:19 am    Post subject: SQL Query Error in WMB Reply with quote

Apprentice

Joined: 13 Jun 2011
Posts: 47

I'm getting a SQL Exception while using variables in the executeQuery argument as below.
Code:
ResultSet rs1 = stmt.executeQuery("INSERT INTO MYORDERS (ORDER_ID, ORDER_STATUS) VALUES (refOrderId, refOrderStatus)");


The exception is :
ora-00984 column not allowed here in WMB

But if I hard code the values like below, it works fine.
Code:
ResultSet rs1 = stmt.executeQuery("INSERT INTO MYORDERS (ORDER_ID, ORDER_STATUS) VALUES (1234, 'status')");


Can anyone say what should be done to resolve this problem since I can't use hard coded value here.
Back to top
View user's profile Send private message
adubya
PostPosted: Wed Feb 29, 2012 2:26 am    Post subject: Reply with quote

Partisan

Joined: 25 Aug 2011
Posts: 377
Location: GU12, UK

The problem here is that your SQL string is passed literally to Oracle which then attempts to resolve refOrderId and refOrderStatus. As these are presumably variables in your Java code which Oracle has no visibility of then it throws an error. Use a prepared statement in Java like
Quote:
"INSERT INTO MYORDERS (ORDER_ID, ORDER_STATUS) VALUES (?, ?)"


and when you invoke it pass refOrderId and refOrderStatus as arguments to your Java prepared statement execution method.

I can't remember the Java methods to create/run a prepared statement so haven't included them above but some simple searching of the documentation will find them
Back to top
View user's profile Send private message Send e-mail
SDS
PostPosted: Wed Feb 29, 2012 2:37 am    Post subject: Reply with quote

Apprentice

Joined: 13 Jun 2011
Posts: 47

Thanks adubya.
But i don't have any idea how to use Java Prepare Statement in WMB Java Compute Node. Do I have to include it as ResultSet argument?
Can you please give me any example of it?
Back to top
View user's profile Send private message
adubya
PostPosted: Wed Feb 29, 2012 2:43 am    Post subject: Reply with quote

Partisan

Joined: 25 Aug 2011
Posts: 377
Location: GU12, UK

Actually I can't see any mention of a prepared statement method in the documentation.

So an alternative (no so nice) method would be to build up your SQL string as follows:-

Code:
ResultSet rs1 = stmt.executeQuery("INSERT INTO MYORDERS (ORDER_ID, ORDER_STATUS) VALUES ("+refOrderId+","+ refOrderStatus+")");
Back to top
View user's profile Send private message Send e-mail
adubya
PostPosted: Wed Feb 29, 2012 2:55 am    Post subject: Reply with quote

Partisan

Joined: 25 Aug 2011
Posts: 377
Location: GU12, UK

Found the prepared statement stuff.

http://docs.oracle.com/javase/1.4.2/docs/api/java/sql/Connection.html#prepareStatement(java.lang.String)

Code:
PreparedStatement stmt = conn.prepareStatement ( "INSERT INTO MYORDERS (ORDER_ID, ORDER_STATUS) VALUES (?, ?)");

stmt.setInt(1, refOrderId);   /* Assumes ORDER_ID is an integer column */
stmt.setString(2, refOrderStatus);
stmt.execute();
stmt.close();
Back to top
View user's profile Send private message Send e-mail
SDS
PostPosted: Wed Feb 29, 2012 3:17 am    Post subject: Reply with quote

Apprentice

Joined: 13 Jun 2011
Posts: 47

Thanks a lot for the help!!
but now its throwing a Null Pointer Exception while executing the PreparedStatement line.
Back to top
View user's profile Send private message
adubya
PostPosted: Wed Feb 29, 2012 3:25 am    Post subject: Reply with quote

Partisan

Joined: 25 Aug 2011
Posts: 377
Location: GU12, UK

SDS wrote:
Thanks a lot for the help!!
but now its throwing a Null Pointer Exception while executing the PreparedStatement line.


I have assumed that the conn variable is populated with a legit Connection object. Is this the case ?
Back to top
View user's profile Send private message Send e-mail
SDS
PostPosted: Wed Feb 29, 2012 4:14 am    Post subject: Reply with quote

Apprentice

Joined: 13 Jun 2011
Posts: 47

yes.. there was silly mistake in Connection parameter..
the issue is resolved now.

thanks a lot abudya..

i have another problem in converting timestamp from string data type to timestamp data type. i am using the following code.

Code:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
java.util.Date businessDayDate = dateFormat.parse(XbusinessDayDate);

e.g. String XbusinessDayDate = "2012-02-01 10:20:30"

but here the businessDayDate variable takes the value as "Date" only.

do you have any idea how can we convert string "2012-02-01 10:20:30" to timestamp 2012-02-01 10:20:30 to insert it as timestamp in DB?

Also in Prepared Statement if I try to set the Date Variable as below

stmt.setDate(5, businessDayDate);

it gives error as :
Code:
The method setDate(int, Date) in the type PreparedStatement is not applicable for the arguments (int, Date)


Any body having any idea on the above issues plz help out!


Last edited by SDS on Wed Feb 29, 2012 4:51 am; edited 2 times in total
Back to top
View user's profile Send private message
McueMart
PostPosted: Wed Feb 29, 2012 4:42 am    Post subject: Reply with quote

Chevalier

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

Just a shot in the dark:

Is the stmt.setDate(...) method expecting a java.sql.Date instead of the java.util.Date which you are passing in?
Back to top
View user's profile Send private message
SDS
PostPosted: Wed Feb 29, 2012 4:53 am    Post subject: Reply with quote

Apprentice

Joined: 13 Jun 2011
Posts: 47

Hi

The problem is resolved!!

I have used below statement directly.

Code:
stmt.setTimestamp(5, Timestamp.valueOf(XbusinessDayDate))


And it solved both the problems..

Cheers!!
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 » SQL Query Error in WMB
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.