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 > db2 prevent update operation

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-09-12, 06:06
sasindrane sasindrane is offline
Registered User
 
Join Date: Jan 2012
Posts: 1
db2 prevent update operation

Hi all,
I have created a table "customer" in DB2 with 5 columns, the 1st column ID as an int type with auto increment identity and other 4 columns are string .
When am running the below code with "delete" operation it work successfully but am running with "Insert" operation it shows an error given below.

???????
*******************************Error************** ****
An error Occured
com.ibm.pdq****ntime.exception.DataRuntimeExceptio n: [pdq][10107][3.10.156] An error prevented the update operation from completing successfully.; Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: The number of values assigned is not the same as the number of specified or implied columns or variables.. SQLCODE=-117, SQLSTATE=42802, DRIVER=4.12.79
at com.ibm.pdq****ntime.internal.db.JdbcData.update_( JdbcData.java:605)
at com.ibm.pdq****ntime.internal.db.DataImpl.update(D ataImpl.java:545)
at com.project.InlineTest.main(InlineTest.java:30)
Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: The number of values assigned is not the same as the number of specified or implied columns or variables.. SQLCODE=-117, SQLSTATE=42802, DRIVER=4.12.79
at com.ibm.db2.jcc.am.hd.a(hd.java:676)
at com.ibm.db2.jcc.am.hd.a(hd.java:60)
at com.ibm.db2.jcc.am.hd.a(hd.java:127)
at com.ibm.db2.jcc.am.on.c(on.java:2633)
at com.ibm.db2.jcc.am.on.d(on.java:2621)
at com.ibm.db2.jcc.am.on.a(on.java:2085)
at com.ibm.db2.jcc.am.pn.a(pn.java:7054)
at com.ibm.db2.jcc.t4.cb.g(cb.java:141)
at com.ibm.db2.jcc.t4.cb.a(cb.java:41)
at com.ibm.db2.jcc.t4.q.a(q.java:32)
at com.ibm.db2.jcc.t4.rb.i(rb.java:135)
at com.ibm.db2.jcc.am.on.ib(on.java:2055)
at com.ibm.db2.jcc.am.pn.rc(pn.java:3219)
at com.ibm.db2.jcc.am.pn.xc(pn.java:3349)
at com.ibm.db2.jcc.am.pn.a(pn.java:583)
at com.ibm.db2.jcc.am.lb.a(lb.java:2236)
at com.ibm.db2.jcc.am.lb.prepareStatement(lb.java:270 9)
at com.ibm.pdq****ntime.internal.wrappers.ConnectionE xecutionHandler.callPrepareStatementForAGKOnPhysic alConnection(ConnectionExecutionHandler.java:2560)
at com.ibm.pdq****ntime.internal.wrappers.ConnectionE xecutionHandler.prepareStatementForAGKs(Connection ExecutionHandler.java:2500)
at com.ibm.pdq****ntime.internal.wrappers.db2.DB2Conn ectionExecutionHandler.prepareStatementForAGKs(DB2 ConnectionExecutionHandler.java:317)
at com.ibm.pdq****ntime.internal.wrappers.ConnectionE xecutionHandler.invoke(ConnectionExecutionHandler. java:1336)
at com.ibm.pdq****ntime.internal.proxy.ProxiedJdbcCon nectionInvocationHandler.createStatementProxy(Prox iedJdbcConnectionInvocationHandler.java:330)
at com.ibm.pdq****ntime.internal.proxy.ProxiedJdbcCon nectionInvocationHandler.invoke(ProxiedJdbcConnect ionInvocationHandler.java:158)
at $Proxy0.prepareStatement(Unknown Source)
at com.ibm.pdq****ntime.internal.db.db2.DB2JdbcData.g etPreparedStatement(DB2JdbcData.java:525)
at com.ibm.pdq****ntime.internal.db.JdbcData.prepareS tatementAndSetInputParameters(JdbcData.java:201)
at com.ibm.pdq****ntime.internal.db.JdbcData.update_( JdbcData.java:564)
... 2 more

************************************************** **
**************************Code******************** **
package com.project;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;
import com.ibm.pdq****ntime.Data;
import com.ibm.pdq****ntime.factory.DataFactory;

public class InlineTest
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Connection conn=null;
String sql=null;
String insertSql=null;

try
{ conn=InlineTest.getConnection1();
Data data=DataFactory.getData(conn);

insertSql="INSERT INTO ADMIN.CUSTOMER VALUES(:name,:country,:street,:city)";

Customer addCustomer=new Customer("sas","india","kdy","kdy");
System.out.println("Pass I");
int insertcount=data.update(insertSql,addCustomer );
System.out.println("Pass II");
System.out.println("Inserted Count:"+insertcount);



//data.update("delete from ADMIN.CUSTOMER");
conn.close();
}catch(Exception ee)
{
System.out.println("An error Occured");
ee.printStackTrace();
}


}
public static Connection getConnection1()
{
Connection connection=null;
try
{
Class.forName("com.ibm.db2.jcc.DB2Driver").newInst ance();
Properties info=new Properties();
info.put("retrieveMessagesFromServerOnGetMessage", "true");
info.put("user","admin");
info.put("password", "adminp");
String url="jdbc:db2://localhost:50000/TEST:deferPrepares=false;";
connection=DriverManager.getConnection(url,info);

}catch(Exception e)
{
e.printStackTrace();
}
return connection;
}

}
Reply With Quote
  #2 (permalink)  
Old 01-09-12, 06:12
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Add column names after table name in INSERT statement.
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