If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > JDBC problem for INSERT INTO...SELECT statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-23-07, 23:05
desmondtanck desmondtanck is offline
Registered User
 
Join Date: Apr 2007
Posts: 23
JDBC problem for INSERT INTO...SELECT statement

When i tried to execute the exact statement in the DB2 Control Center GUI
it works perfectly, but when i use it from JAVA, it prompts error.
com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -418, SQLSTATE: 42610, SQLERRMC: null

below is the similar statement:
Insert into
table1(uid,username,createby,register_date)
Select
a.uid,
b.username,
'admin',
current_timestamp
from
table2 as a,
table3 as b
where
a.uid= 102
and
a.uid=b.uid

Last edited by desmondtanck; 04-24-07 at 04:17.
Reply With Quote
  #2 (permalink)  
Old 04-24-07, 01:51
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,
are you sure this is working in DB2 Control Center?

Insert into
table1(uid,username,createby,register_date)
Select
a.uid,
b.username,
'admin',
current_timestamp
from
table2 as a,
table3 as b, <-- use without comma!
where
a.uid= 102
and
a.uid=b.uid

Hope this helps,
Grofaty
Reply With Quote
  #3 (permalink)  
Old 04-24-07, 01:57
desmondtanck desmondtanck is offline
Registered User
 
Join Date: Apr 2007
Posts: 23
actually the statement is simplified from my original statement,
so you can avoid the comma,
it really works in the control center.
Reply With Quote
  #4 (permalink)  
Old 04-24-07, 02:22
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by desmondtanck
actually the statement is simplified from my original statement, so you can avoid the comma, it really works in the control center.
Then try avoiding the comma in Java, too.
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #5 (permalink)  
Old 04-24-07, 04:16
desmondtanck desmondtanck is offline
Registered User
 
Join Date: Apr 2007
Posts: 23
actually that is just a spelling mistake when i post this title
there is nothing to do with my original statement,
i mean it really can be executed at control center

but it somehow throw exception when i use it at Java.
Reply With Quote
  #6 (permalink)  
Old 04-24-07, 06:41
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,
have you checked the error message documentation?
Code:
SQL0418N A statement contains a use of a parameter marker that
          is not valid.

Explanation:

Untyped parameter markers cannot be used:

o   in a SELECT list

o   as the sole argument of a datetime arithmetic operation

o   in some cases as the sole argument of a scalar function

o   as a sort key in an ORDER BY clause



 Parameter markers can never be used:

o   in a statement that is not a prepared statement

o   in the fullselect of a CREATE VIEW statement

o   in the triggered action of a CREATE TRIGGER statement

o   in a query captured by DB2 Query Patroller



 The statement cannot be processed.

User Response:

Correct the syntax of the statement.  If untyped parameter
markers are not allowed, use the CAST specification to give the
parameter marker a data type.

 sqlcode :  -418

 sqlstate :  42610
Reply With Quote
  #7 (permalink)  
Old 04-24-07, 07:53
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Did I get this right that you post a statement here that has nothing to do with your actual query? And the actual query fails in your application but supposedly works in CC?

Does the statement you posted here work in CC and fail in your application? If the answer is no (same behavior in both cases), then it is completely useless here...
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #8 (permalink)  
Old 04-24-07, 23:26
desmondtanck desmondtanck is offline
Registered User
 
Join Date: Apr 2007
Posts: 23
Thanks for your replies,

yes, it has nothing to do with my actual query as i cant post the real query here, just to tell that the real query is similar to the one i've posted.

What i want to make sure is that, is it possible that some query can be executed in CC and will fail when i execute using my application?
Reply With Quote
  #9 (permalink)  
Old 04-25-07, 00:46
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,
it shouldn't be working like that. Query is query. Are you sure your JDBC connection is working properly? What is your operating system name and version? What is you db2 edition and version (commands: db2level , db2licm -l)?

Try using db2ca from command shell and test your JDBC connection. Is it working properly?

Are you 100% sure the same query is working on CC and JDBC?

Hope this helps,
Grofaty
Reply With Quote
  #10 (permalink)  
Old 04-25-07, 02:40
desmondtanck desmondtanck is offline
Registered User
 
Join Date: Apr 2007
Posts: 23
yes, my jdbc can work perfectly with other statement,
i can even successfully login to my system using db2.
until i'm trying to do some INSERT INTO...SELECT..statement, it fails.

i'm using DB2 Express Edition 9.1, the db2 is stored at Linux, and i
have my application at Window 2000.

the jdbc works with other query at my application, so that means that
it works correctly right?
Reply With Quote
  #11 (permalink)  
Old 04-25-07, 02:57
desmondtanck desmondtanck is offline
Registered User
 
Join Date: Apr 2007
Posts: 23
I've found out a weird thing here,
i tried to remove the WHERE clause from my actual query,
it works fine.
For example,
insert into table1(username,createdate) select username, current_timestamp
from table2

The example above works fine in my application, but when i add the WHERE clause, it fails....
insert into table1(username,createdate) select username, current_timestamp
from table2 where username='tanck'

it is the WHERE clause make the query fails, any suggestion?

Thanks,
Desmond
Reply With Quote
  #12 (permalink)  
Old 04-25-07, 04:53
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Quote:
Originally Posted by desmondtanck
What i want to make sure is that, is it possible that some query can be executed in CC and will fail when i execute using my application?
No, that (usually) not possible.

CC uses JDBC to talk to DB2 - as does your application. So you have the same environment. Therefore, I believe you some other differences between your app and JDBC.

The real problem is that you didn't show us a query that works in one case and fails in the other. You should find such a query (which you can post here), first.

What I recommend right now is that you collect a JDBC trace to see what is really going on in the communication with DB2. There you may see something...
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #13 (permalink)  
Old 04-25-07, 05:12
desmondtanck desmondtanck is offline
Registered User
 
Join Date: Apr 2007
Posts: 23
Statement 1:
insert into table1(username,access_time) select username, current_timestamp from table2

Statement 1 works fine in my application and CC.

Statement 2:
insert into table1(username,access_time) select username, current_timestamp from table2 where uid=102

Statement 2 fails at my application but works nicely at CC. where uid is the auto increment primary key of table2.
Reply With Quote
  #14 (permalink)  
Old 04-25-07, 08:14
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
What sort of JDBC construct (java.sql.Statement, java.sql.PreparedStatement, etc) are you using? Could you post the jdbc code that is failing?

Andy
Reply With Quote
  #15 (permalink)  
Old 04-25-07, 12:22
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
...and what's the JDBC trace saying?
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On