pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: pprotim <pprotim80@yahoo.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Not able to insert array of integers into column of type integer array
Date: Mon, 1 Oct 2012 09:08:55 -0700 (PDT)
Message-ID: <1349107725.96229.YahooMailNeo@web120301.mail.ne1.yahoo.com> (raw)
In-Reply-To: <506328AC.2070206@tu-braunschweig.de>
References: <1348674063961-5725537.post@n5.nabble.com>
	<506328AC.2070206@tu-braunschweig.de>





________________________________
 From: Stefan Reiser [via PostgreSQL] <ml-node+s1045698n5725550h71@n5.nabble.com>
To: pprotim <pprotim80@yahoo.com> 
Sent: Wednesday, September 26, 2012 9:40 PM
Subject: Re: Not able to insert array of integers into column of type integer array
 

When setting or updating arrays in a ResultSet or PreparedStatement you 
can't use java array types (Integer[], ...) -- they need to be wrapped 
in a "java.sql.Array". This is done using the Connection-object. 

here's an example with Floats: 

    Connection con = // your connection 
    Double[] dbArr =  // ... some java array 
    Array sqlArray = con.createArrayOf("float8", dbArr); 

Now "sqlArray" can be used with setArray() (or even setObject() ). 
(not sure where, but there were some other examples in the JDK-docs or 
pg-JDBC-docs ...) 


pprotim schrieb: 

> Hi, 
> 
> I am trying to insert a row to a column in a table which is of data type 
> INT4[]. I am not sure what should be the code in java I should write so that 
> I can write the insert query. Exception I am getting below: 
> Help needed!!!! 
> 
> 
> junit.framework.AssertionFailedError: PreparedStatementCallback; bad SQL 
> grammar [INSERT INTO ORGANIZATION_STRUCTURE 
> (ID_ORGANIZATION_STRUCTURE,ID_CLIENT,ORG_LEVEL,AR_ORG_MAP,ID_SUP_LEVEL,ORG_NAME,TIMEZONE_ABREV,ORG_CURRENCY_CODE_ALPHA) 
> VALUES(NEXTVAL('SEQ_ORGANIZATION_STRUCTURE'),?,?,?,?,?,?,?)]; nested 
> exception is org.postgresql.util.PSQLException: Can't infer the SQL type to 
> use for an instance of [Ljava.lang.Integer;. Use setObject() with an 
> explicit Types value to specify the type to use. 
> 	at junit.framework.Assert.fail(Assert.java:50) 
> 	at 
> com.ingenico.atlas.integration.eportal.dao.CustomerDAOTest.createOrgStructureTest(CustomerDAOTest.java:59) 
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> 	at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
> 	at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
> 	at java.lang.reflect.Method.invoke(Method.java:597) 
> 	at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) 
> 	at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
> 	at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) 
> 	at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
> 	at 
> org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) 
> 	at 
> org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) 
> 	at 
> org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) 
> 	at 
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) 
> 	at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) 
> 	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) 
> 	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) 
> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) 
> 	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) 
> 	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) 
> 	at 
> org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 
> 	at 
> org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) 
> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:300) 
> 	at 
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) 
> 	at 
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 
> 	at 
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
> 	at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
> 	at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
> 	at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
> 	at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 
> 
> 
> 
> 
> -- 
> View this message in context: http://postgresql.1045698.n5.nabble.com/Not-able-to-insert-array-of-integers-into-column-of-type-int...
> Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com. 
> 
> 


-- 
Sent via pgsql-jdbc mailing list ([hidden email]) 
To make changes to your subscription: 
http://www.postgresql.org/mailpref/pgsql-jdbc


________________________________
 
If you reply to this email, your message will be added to the discussion below:http://postgresql.1045698.n5.nabble.com/Not-able-to-insert-array-of-integers-into-column-of-type-int... 
To unsubscribe from Not able to insert array of integers into column of type integer array, click here.
NAML



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Not-able-to-insert-array-of-integers-into-column-of-type-int...
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.

view thread (4+ messages)  latest in thread

Message-ID: <1349107725.96229.YahooMailNeo@web120301.mail.ne1.yahoo.com>
Permalink:  ../1349107725.96229.YahooMailNeo@web120301.mail.ne1.yahoo.com/
Also on:    postgresql.org/message-id/1349107725.96229.YahooMailNeo@web120301.mail.ne1.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: pprotim80@yahoo.com
  Subject: Re: Not able to insert array of integers into column of type integer array
  In-Reply-To: <1349107725.96229.YahooMailNeo@web120301.mail.ne1.yahoo.com>
  References: <1348674063961-5725537.post@n5.nabble.com> <506328AC.2070206@tu-braunschweig.de> <1349107725.96229.YahooMailNeo@web120301.mail.ne1.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox