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 > Insert an integer with quotes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-12-09, 07:07
dag79 dag79 is offline
Registered User
 
Join Date: Jan 2009
Posts: 2
Question Insert an integer with quotes

Hi All,
I have a big problem. I need to insert data into a DB2 database (details below) from a java client (via JDBC). The problem is that I don't know the type of the columns so the insertion is: INSERT into TABLE1 (col1,col2) values ('value1','value2'), where value1 and value2 may be an integer or a String.
I try to better explain, my client receives 5 values and it doesn't know the structure of the db, it knows that the first values is the table name, the second and the third are the name of columns and the fourth and fifth are the values, but it doesn't know the type (INT,CHAR,....). This client uses four different db, SQL server, mysql, Informix and DB2. For all the others db I add the quotes for each value (like in the insert above) and the insertion ends with success, instead DB2 returns an error, it doesn't succeed to make the insertion.
How can I force the insertion? Is there a configuration value to set to allow the insertion to succeed?
For the test I created a test table (TestTable (id INTEGER, name VARCHAR)) and I want to make this insertion: INSERT into TestTable (id,name) values ('1','Tom').

Details DB2:
DB2 Express-C
version: v9.5.0.808
Fix Pack: 0

Details OS:
Windows XP Professional 2002
Service pack 3


Many Thanks
Davide Guidotti
Reply With Quote
  #2 (permalink)  
Old 01-12-09, 08:12
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You cannot do it the way you want. Instead you will have to to it the correct way. You are given the the table name and column names. Use this information to query the DB as to the type of data. Then set the data based on this information.

Andy
Reply With Quote
  #3 (permalink)  
Old 01-12-09, 08:54
dag79 dag79 is offline
Registered User
 
Join Date: Jan 2009
Posts: 2
Thank Andy, but I can't do that, I don't have this kind of control. It's hard to explain, but what's happen is that I execute the client only the first time, then it creates a sequential "workflow" (is not a real workflow, it's a list of operation without condition) that will be executed from a web service. In this "workflow" I can't insert an "If..Then..Else" condition, I mean, I can query the DB and get the type, but I can't create a different query based on response. What I need is something that allows me to submit the query anyway,but, if I well understand, it's impossible.

Thanks again
Davide
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