ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jishnu123 <rjis...@gmail.com>
Subject Re: IBatis Array feild insertion problem in postgres database()Please help me)
Date Mon, 26 Oct 2009 10:51:19 GMT


Dear Ingmar Lötzsch,


                Still, I am facing the problem  for inserting array field
through  iBatis..
Current error list as  follows...

Errors List in insert groups::::::::::::::SqlMapClient operation;
uncategorized SQLException for SQL []; SQL state [null]; error code [0];   
--- The error occurred in org/ada/kms/sqlmap/KmsgroupSQLMap.xml.  
--- The error occurred while applying a parameter map.  
--- Check the kmsgroups.insertgroups-InlineParameterMap.  
--- Check the parameter mapping for the 'kmsgrpaccessiblegroup' property.  
--- Cause: java.lang.ClassCastException: org.ada.kms.domain.IntArray cannot
be cast to java.util.Collection; nested exception is
com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in org/ada/kms/sqlmap/KmsgroupSQLMap.xml.  
--- The error occurred while applying a parameter map.  
--- Check the kmsgroups.insertgroups-InlineParameterMap.  
--- Check the parameter mapping for the 'kmsgrpaccessiblegroup' property.  
--- Cause: java.lang.ClassCastException: org.ada.kms.domain.IntArray cannot
be cast to java.util.Collection


If you get any idea please sent me immediately......

Ingmar Lötzsch wrote:
> 
> Look at the stacktrace:
> 
>> Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
>> --- The error occurred in org/ada/kms/sqlmap/KmsgroupSQLMap.xml.
>> --- The error occurred while applying a parameter map.
>> --- Check the kmsgroups.insertgroups-InlineParameterMap.
>> --- Check the parameter mapping for the 'kmsgroupactive' property.
> 
> The INSERT failed because of an NullPointerException.
> 
> Seems this is related to property kmsgroupactive.
> 
> What type is kmsgroupactive?
> 
> What is the actual value of kmsgroupactive during excution?
> 
> Set a breakpoint in your DAO and inspect the parameters.
> 
> Seems your problem is not related to the array.
> 
> jishnu123 schrieb:
>> 
>> Hai,
>> 
>> Thank you for your reply....I got exception details as follows.....please
>> reply immediately...
>> 
>> org.springframework.jdbc.UncategorizedSQLException: SqlMapClient
>> operation;
>> uncategorized SQLException for SQL []; SQL state [null]; error code [0];   
>> --- The error occurred in org/ada/kms/sqlmap/KmsgroupSQLMap.xml.  
>> --- The error occurred while applying a parameter map.  
>> --- Check the kmsgroups.insertgroups-InlineParameterMap.  
>> --- Check the parameter mapping for the 'kmsgroupactive' property.  
>> --- Cause: java.lang.NullPointerException; nested exception is
>> com.ibatis.common.jdbc.exception.NestedSQLException:   
>> --- The error occurred in org/ada/kms/sqlmap/KmsgroupSQLMap.xml.  
>> --- The error occurred while applying a parameter map.  
>> --- Check the kmsgroups.insertgroups-InlineParameterMap.  
>> --- Check the parameter mapping for the 'kmsgroupactive' property.  
>> --- Cause: java.lang.NullPointerException
>> Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:   
>> --- The error occurred in org/ada/kms/sqlmap/KmsgroupSQLMap.xml.  
>> --- The error occurred while applying a parameter map.  
>> --- Check the kmsgroups.insertgroups-InlineParameterMap.  
>> --- Check the parameter mapping for the 'kmsgroupactive' property.  
>> --- Cause: java.lang.NullPointerException
>> 	at
>> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:110)
>> 	at
>> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:393)
>> 	at
>> com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82)
>> 	at
>> org.springframework.orm.ibatis.SqlMapClientTemplate$9.doInSqlMapClient(SqlMapClientTemplate.java:370)
>> 	at
>> org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:194)
>> 	at
>> org.springframework.orm.ibatis.SqlMapClientTemplate.insert(SqlMapClientTemplate.java:368)
>> 	at
>> org.ada.kms.daoimpl.KmsAddServiceImpl.insertGroups(KmsAddServiceImpl.java:98)
>> 	at
>> org.ada.kms.formcontrollers.KmsGroupsFormController.onSubmit(KmsGroupsFormController.java:70)
>> 	at
>> org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:267)
>> 	at
>> org.springframework.web.servlet.mvc.AbstractFormController.handleInvalidSubmit(AbstractFormController.java:671)
>> 	at
>> org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:272)
>> 	at
>> org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
>> 	at
>> org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
>> 	at
>> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:859)
>> 	at
>> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:793)
>> 	at
>> org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
>> 	at
>> org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
>> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
>> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>> 	at
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
>> 	at
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>> 	at
>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
>> 	at
>> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
>> 	at
>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
>> 	at
>> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>> 	at
>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>> 	at
>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
>> 	at
>> org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:852)
>> 	at
>> org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:584)
>> 	at
>> org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)
>> 	at java.lang.Thread.run(Thread.java:619)
>> Caused by: java.lang.NullPointerException
>> 	at
>> com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameter(ParameterMap.java:166)
>> 	at
>> com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameters(ParameterMap.java:126)
>> 	at
>> com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:78)
>> 	at
>> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteUpdate(MappedStatement.java:216)
>> 	at
>> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:94)
>> 	... 30 more
>> Errors List in insert groups::::::::::::::SqlMapClient operation;
>> uncategorized SQLException for SQL []; SQL state [null]; error code [0];   
>> --- The error occurred in org/ada/kms/sqlmap/KmsgroupSQLMap.xml.  
>> --- The error occurred while applying a parameter map.  
>> --- Check the kmsgroups.insertgroups-InlineParameterMap.  
>> --- Check the parameter mapping for the 'kmsgroupactive' property.  
>> --- Cause: java.lang.NullPointerException; nested exception is
>> com.ibatis.common.jdbc.exception.NestedSQLException:   
>> --- The error occurred in org/ada/kms/sqlmap/KmsgroupSQLMap.xml.  
>> --- The error occurred while applying a parameter map.  
>> --- Check the kmsgroups.insertgroups-InlineParameterMap.  
>> --- Check the parameter mapping for the 'kmsgroupactive' property.  
>> --- Cause: java.lang.NullPointerException
>> 
>> 
>> 
>> 
>> 
>> 
>> Ingmar Lötzsch wrote:
>>>>> INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
>>> INFO does not mean there was thrown an exception.
>>>
>>> What exceptions do you get?
>>>
>>> Are you certain all methods are invoked?
>>>
>>> Can you set breakpoints in
>>>
>>> - KmsGroup.getKmsgrpaccessiblegroup()
>>> - ...DAO.insertGroups(KmsGroup kmsgroup)
>>>
>>> and debug the program?
>>>
>>> Consider to take all Java code out of the JSP. Nowadays it's a bad
>>> practice to intermingle HTML and Java code.
>>>
>>> When plain JDBC works, make a test with iBATIS only. When this works,
>>> make a test with Spring and iBATIS out of the webapp. When this works,
>>> test your webapp.
>>>
>>> Ingmar
>>>
>>> jishnu123 schrieb:
>>>> Dear Ingmar Lötzsch,
>>>>
>>>> Thank you for your reply.You send that  code is  working fine..Normal
>>>> code 
>>>> it was worked .
>>>> Problem for integration of spring mvc with iBatis....
>>>> I have  put some related code as follows....
>>>>
>>>> 1)My jsp page
>>>>
>>>> <td align="left"  width="200">
>>>> 					<label for="Othergroups">Other Accessible Groups :</label>
>>>>    				</td>
>>>> 				<td align="left" width="100"><select name="kmsgrpaccessiblegroups"
>>>> 		class="hintanchor" onMouseover="showhint('Please choose  other groups
>>>> Should consist of drag and drop list.', this, event, '200px')"
>>>> 		multiple="multiple" style="width: 140px" size="4">
>>>> 			<%
>>>> 					for(int i=0; i<oGroupArraylist.size(); i++) {
>>>> 					    obKmsgroup = (KmsGroup)oGroupArraylist.get(i);
>>>> 					%>
>>>> 			<option name="<%=obKmsgroup.getKmsgrpgroupname()%>"
>>>> 			
>>>> value="<%=obKmsgroup.getKmsgrpgroupid()%>"><%=obKmsgroup.getKmsgrpgroupname()%></option>
>>>> 			<%
>>>> 					}
>>>> 	
>>>> 					%>
>>>> 		</select></td>
>>>>
>>>> 2)domain class
>>>>
>>>>        private int[] kmsgrpaccessiblegroups;
>>>> 	private IntArray kmsgrpaccessiblegroup;
>>>> 	
>>>> 	public IntArray getKmsgrpaccessiblegroup() {
>>>> 	    return kmsgrpaccessiblegroup;
>>>> 	}
>>>> 	public void setKmsgrpaccessiblegroup(IntArray kmsgrpaccessiblegroup) {
>>>> 	    this.kmsgrpaccessiblegroup = kmsgrpaccessiblegroup;
>>>> 	}
>>>> public int[] getKmsgrpaccessiblegroups() {
>>>> 	    return kmsgrpaccessiblegroups;
>>>> 	}
>>>> 	public void setKmsgrpaccessiblegroups(int[] kmsgrpaccessiblegroups) {
>>>> 	    this.kmsgrpaccessiblegroups = kmsgrpaccessiblegroups;
>>>> 	    logger.info("setKmsgrpaccessiblegroups  set to "
>>>> +kmsgrpaccessiblegroups);
>>>> 	}
>>>>
>>>> 3)FormController
>>>>
>>>> int[] arrayData=obkmsgroup.getKmsgrpaccessiblegroups();
>>>> 	
>>>> 		for(int i=0;i<arrayData.length;i++)
>>>> 	    System.out.println("The data of the array=="+arrayData[i]);
>>>> 	IntArray intArray = new IntArray(arrayData);
>>>> 	logger.info("INT ARRAY DETAILS=="+intArray);
>>>> 	obkmsgroup.setKmsgrpaccessiblegroup(intArray);
>>>> 4)Dao Implementatiion
>>>>  public  void insertGroups(KmsGroup kmsgroup)throws Exception{
>>>> 	logger.info("Start Executing query for insert kmsgroups");
>>>> 	template.insert("kmsgroups.insertgroups",kmsgroup);
>>>>     }
>>>> 4)Mapping file
>>>> <typeAlias alias="IntArrayTypeHandler"
>>>> type="org.ada.kms.domain.IntArrayTypeHandler"/> 
>>>>   <insert id="insertgroups" parameterClass="kmsgroup">
>>>>    		   
>>>>    INSERT INTO
>>>> kms.kms_group(kms_grp_groupid,kms_grp_groupname,kms_group_active,kms_grp_description,kms_grp_createdon,kms_grp_createdby,kms_grp_accessiblegroup)

>>>>       
>>>> VALUES(#kmsgrpgroupid#,#kmsgrpgroupname#,#kmsgroupactive#,#kmsgrpdescription#,#kmsgrpcreatedon#,#kmsgrpcreatedby#,
>>>>        #kmsgrpaccessiblegroup,handler=IntArrayTypeHandler#)
>>>>  
>>>>    </insert>
>>>>
>>>> 5)Alraedy implemented java beans  like IntArray,SqlArrayAdapter, and
>>>> IntArrayTypeHandler
>>>>
>>>>
>>>> The same message get the eclipse console as follows..
>>>>
>>>>> INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
-
>>>>> <Loading XML bean definitions from class path resource
>>>>> [org/springframework/jdbc/support/sql-error-codes.xml]>
>>>>>  INFO [org.springframework.jdbc.support.SQLErrorCodesFactory] -
>>>>> <SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL,
>>>>> Oracle, PostgreSQL, Sybase]> 
>>>>  
>>>> Any idea u get please reply immediately....
>>>>
>>>> Ingmar Lötzsch wrote:
>>>>> Can you post the exceptions?
>>>>>
>>>>> Can you do the following:
>>>>>
>>>>> On SQL-client (Console/pgAdmin)
>>>>>
>>>>> CREATE TABLE arraytest
>>>>> (
>>>>> 	id int NOT NULL PRIMARY KEY,
>>>>> 	intarray int[] NOT NULL
>>>>> )
>>>>> WITHOUT OIDS;
>>>>>
>>>>> INSERT INTO arraytest (id, intarray) VALUES (1, ARRAY[1, 2]);
>>>>> INSERT INTO arraytest (id, intarray) VALUES (2, '{1, 3}' :: int[]);
>>>>>
>>>>> Can you than execute the following code using class IntArray:
>>>>>
>>>>> import java.sql.Connection;
>>>>> import java.sql.DriverManager;
>>>>> import java.sql.PreparedStatement;
>>>>>
>>>>> public class ArrayTest
>>>>> {
>>>>> 	public static void main(String[] args)
>>>>> 	{
>>>>> 		try
>>>>> 		{
>>>>> 			Class.forName("org.postgresql.Driver");
>>>>> 			String url = "jdbc:postgresql://localhost/test";
>>>>> 			Connection con = DriverManager.getConnection(url, "postgres",
>>>>> "admin");
>>>>> 			
>>>>> 			String sql = "INSERT INTO arraytest (id, intarray) VALUES (?, ?)";
>>>>> 			PreparedStatement pstmt = con.prepareStatement(sql);
>>>>> 			pstmt.setInt(1, 3);
>>>>> 			int[] ints = {2, 4};
>>>>> 			IntArray intArray = new IntArray(ints);
>>>>> 			pstmt.setArray(2, intArray);
>>>>> 			int rows = pstmt.executeUpdate();
>>>>> 			System.out.println(rows);
>>>>> 			pstmt.close();
>>>>> 			con.close();
>>>>> 		}
>>>>> 		catch (Exception e)
>>>>> 		{
>>>>> 			e.printStackTrace(System.out);
>>>>> 		}
>>>>> 	}
>>>>> }
>>>>>
>>>>> Do you get any exceptions?
>>>>>
>>>>> jishnu123 schrieb:
>>>>>> I have already implemented all java beans with
>>>>>> SqlArrayAdapter,IntArray
>>>>>> and
>>>>>> IntArrayTypeHandler..But iam still facing the same
>>>>>> problem....Actually
>>>>>> i
>>>>>> had
>>>>>> implemented my project using spring mvc with iBatis..I think spring
>>>>>> MVC
>>>>>> problem...
>>>>>>
>>>>>> I again mention that particular error as follows....Any body have
any
>>>>>> idea
>>>>>> to solve that problem... Please sent reply immediately... 
>>>>>>
>>>>>> INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
>>>>>> -
>>>>>> <Loading XML bean definitions from class path resource
>>>>>> [org/springframework/jdbc/support/sql-error-codes.xml]>
>>>>>>  INFO [org.springframework.jdbc.support.SQLErrorCodesFactory] -
>>>>>> <SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL,
>>>>>> MySQL,
>>>>>> Oracle, PostgreSQL, Sybase]>
>>>>>>
>>>>>>
>>>>>> Rahul Saluja wrote:
>>>>>>> Hi Jishnu,
>>>>>>>
>>>>>>> I cannot understand anything by given exception but yes suggested
>>>>>>> implementation by Ingmar is rite approach and moreover which
version
>>>>>>> of
>>>>>>> Postgres you are using as in 7.3.1 it is nlot possible to store
the
>>>>>>> array
>>>>>>> data so better way of doing it is to convert the data in String
and
>>>>>>> push
>>>>>>> it as varchar  and while retrieving back convert back it into
your
>>>>>>> required datatype array here is the example you can use for
>>>>>>> insertion.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> import java.sql.SQLException;
>>>>>>> import java.sql.Types;
>>>>>>> import java.util.Vector;
>>>>>>>
>>>>>>> import com.hns.hss.nmf.common.util.unilogger.LogFactory;
>>>>>>> import com.hns.hss.nmf.common.util.unilogger.LoggerIf;
>>>>>>> import com.ibatis.sqlmap.client.extensions.ParameterSetter;
>>>>>>> import com.ibatis.sqlmap.client.extensions.ResultGetter;
>>>>>>> import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;
>>>>>>>
>>>>>>> public class ByteArrayToTimeStampHandler implements
>>>>>>> TypeHandlerCallback
>>>>>>> {
>>>>>>> private static LoggerIf log_ =
>>>>>>> LogFactory.getLoggerIf(ArraysToStringTypeHandler.class.getName());
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>         public Object getResult(ResultGetter arg0) throws
>>>>>>> SQLException
>>>>>>>         {
>>>>>>>                 // TODO Auto-generated method stub
>>>>>>>                 return null;
>>>>>>>         }
>>>>>>>
>>>>>>>
>>>>>>>         public void setParameter(ParameterSetter setter, Object
>>>>>>> parameter)
>>>>>>> throws SQLException
>>>>>>>         {
>>>>>>>                 if (parameter == null)
>>>>>>>                 {
>>>>>>>                         setter.setNull(Types.CHAR);
>>>>>>>                 }
>>>>>>>                 else
>>>>>>>                 {
>>>>>>>                         setter.setString(ArraysToString(parameter));
>>>>>>>                 }
>>>>>>>                 // TODO Auto-generated method stub
>>>>>>>
>>>>>>>         }
>>>>>>>
>>>>>>>
>>>>>>>         public Object valueOf(String arg0)
>>>>>>>         {
>>>>>>>                 // TODO Auto-generated method stub
>>>>>>>                 return null;
>>>>>>>         }
>>>>>>>
>>>>>>>
>>>>>>>         private String ArraysToString(Object obj)
>>>>>>>         {
>>>>>>>                 if (obj == null)
>>>>>>>                 {
>>>>>>>                         throw new IllegalArgumentException("Could
>>>>>>> not
>>>>>>> convert null to a String value. " + "Valid argument is an array
of
>>>>>>> type
>>>>>>> I_U8  Only ");
>>>>>>>                 }
>>>>>>>
>>>>>>>                 else if (obj instanceof
>>>>>>> com.hns.hss.nmf.server.log.manager.gensrc.Common.I_U8[])
>>>>>>>                 {
>>>>>>>
>>>>>>>         com.hns.hss.nmf.server.log.manager.gensrc.Common.I_U8[]
>>>>>>> ourData
>>>>>>> =
>>>>>>> (com.hns.hss.nmf.server.log.manager.gensrc.Common.I_U8[]) obj;
>>>>>>>                         int length = ourData.length;
>>>>>>>                         Vector byteVector = new Vector();
>>>>>>>                         //byte[] newByteArray = new byte[length-1];
>>>>>>>                         int count = 0;
>>>>>>>
>>>>>>>                         for (int i = 0; i < length; i++)
>>>>>>>                         {
>>>>>>>
>>>>>>>                                 if (ourData[i].getValue() ==
(byte)
>>>>>>> '\0')
>>>>>>> //\0 byte value
>>>>>>>                                 {
>>>>>>>                                         log_.debug(" NULL CHAR
FOUND
>>>>>>> ");
>>>>>>>                                         break;
>>>>>>>                                 }
>>>>>>>                                 else
>>>>>>>                                 {
>>>>>>>                                        
>>>>>>> byteVector.add(ourData[i].getValue());
>>>>>>>                                         count++;
>>>>>>>                                 }
>>>>>>>                         }
>>>>>>>                         log_.debug(" Byte Vector " + byteVector);
>>>>>>>                         String finalHexString = new String();
>>>>>>>                         StringBuffer finalString = new
>>>>>>> StringBuffer();
>>>>>>>                         //String returnString = new String();
>>>>>>>                         try
>>>>>>>                         {
>>>>>>>                                 finalHexString =
>>>>>>> ByteArrayToTimeStampHandler.getHexString(byteVector);
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>                                
>>>>>>> ByteArrayToTimeStampHandler.hexToString(finalHexString,
>>>>>>> finalString);
>>>>>>>                                 log_.debug("finalString is "
+
>>>>>>> finalString.toString());
>>>>>>>
>>>>>>>
>>>>>>>                                 if ( ourData[0].getValue() !=
>>>>>>> (byte)45
>>>>>>> )
>>>>>>> //Not a Negative Sign
>>>>>>>                                  {
>>>>>>>                                  log_.debug(" NOT A NEGATIVE
SIGN
>>>>>>> ");
>>>>>>>                                  returnString = " " + finalString;
>>>>>>>
>>>>>>>
>>>>>>>                                  }else // Negative Sign
>>>>>>>                                  {
>>>>>>>                                                  returnString
= "-"
>>>>>>> +
>>>>>>> finalString;
>>>>>>>
>>>>>>>                                  }
>>>>>>>
>>>>>>>                         }
>>>>>>>                         catch (Exception e)
>>>>>>>                         {
>>>>>>>                                 e.printStackTrace();
>>>>>>>                         }
>>>>>>>
>>>>>>>                         String checkString = finalString.toString();
>>>>>>>                         return checkString;
>>>>>>>
>>>>>>>                 }
>>>>>>>                 else
>>>>>>>                 {
>>>>>>>
>>>>>>>                         return null;
>>>>>>>                 }
>>>>>>>                 //return null;
>>>>>>>
>>>>>>>         }
>>>>>>>
>>>>>>>
>>>>>>>         public static final void hexToString(String hex,
>>>>>>> StringBuffer
>>>>>>> out)
>>>>>>>         {
>>>>>>>                 if (hex == null) return;
>>>>>>>                 int length = hex.length() & -4;
>>>>>>>                 for (int pos = 0; pos < length; pos += 4)
>>>>>>>                 {
>>>>>>>                         int this_char = 0;
>>>>>>>                         try
>>>>>>>                         {
>>>>>>>                 this_char = Integer.parseInt(hex.substring(pos,
pos
>>>>>>> +
>>>>>>> 4),
>>>>>>> 16);
>>>>>>>                         }
>>>>>>>                         catch (NumberFormatException NF_Ex)
>>>>>>>                         {
>>>>>>>                         }
>>>>>>>                         out.append((char) this_char);
>>>>>>>                 }
>>>>>>>         }
>>>>>>>
>>>>>>>         public static String getHexString(Vector vector) throws
>>>>>>> Exception
>>>>>>>         {
>>>>>>>
>>>>>>>                 String result = "00";
>>>>>>>                 short[] b = new short[vector.size()];
>>>>>>>
>>>>>>>                 for (int j = 0; j < vector.size(); j++)
>>>>>>>                 {
>>>>>>>
>>>>>>>                         b[j] = ((Short) vector.get(j)).shortValue();
>>>>>>>                 }
>>>>>>>                 for (int i = 0; i < b.length; i++)
>>>>>>>                 {
>>>>>>>         result += Integer.toString((b[i] & 0xff) + 0x100,
>>>>>>> 16).substring(1);
>>>>>>>                         result += "00";
>>>>>>>                 }
>>>>>>>
>>>>>>>                 return result.substring(0, result.length() -
2);
>>>>>>>         }
>>>>>>> }
>>>>>>> -----Original Message-----
>>>>>>> From: jishnu123 [mailto:rjishnu@gmail.com]
>>>>>>> Sent: Friday, October 09, 2009 10:49 AM
>>>>>>> To: user-java@ibatis.apache.org
>>>>>>> Subject: Re: IBatis Array feild insertion problem in postgres
>>>>>>> database()Please help me)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Thank you for your reply...I have already implemented  type handler
>>>>>>> and
>>>>>>> all
>>>>>>> classes as follows...But i got the the same error as
>>>>>>> follows....Please
>>>>>>> help
>>>>>>> me.....I didn't try array feild selection....I have been trying
to
>>>>>>> insertion
>>>>>>> of array feild...
>>>>>>>
>>>>>>> I have to mention again that error as follows....Any body get
an
>>>>>>> idea
>>>>>>> please
>>>>>>> reply immediately..
>>>>>>>
>>>>>>> INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
>>>>>>> -
>>>>>>> <Loading XML bean definitions from class path resource
>>>>>>> [org/springframework/jdbc/support/sql-error-codes.xml]>
>>>>>>> INFO [org.springframework.jdbc.support.SQLErrorCodesFactory]
-
>>>>>>> <SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL,
>>>>>>> MySQL,
>>>>>>> Oracle, PostgreSQL, Sybase]>
>>>>>>>
>>>>>>>
>>>>>>> Ingmar Lötzsch wrote:
>>>>>>>> You can use a type handler and implement java.sql.Array.
Example:
>>>>>>>>
>>>>>>>> 1st: abstract superclass as adapter
>>>>>>>>
>>>>>>>> public abstract class SqlArrayAdapter
>>>>>>>> implements Array
>>>>>>>> {
>>>>>>>>       public Object getArray() throws SQLException
>>>>>>>>       {
>>>>>>>>               // Auto-generated method stub
>>>>>>>>               return null;
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       public Object getArray(long index, int count) throws
>>>>>>>> SQLException
>>>>>>>>       {
>>>>>>>>               // Auto-generated method stub
>>>>>>>>               return null;
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       public Object getArray(long index, int count, Map<String,
>>>>>>>> Class<
>>>>>>>> ?
>>>>>>>> map) throws SQLException
>>>>>>>>       {
>>>>>>>>               // Auto-generated method stub
>>>>>>>>               return null;
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       public Object getArray(Map<String, Class< ? >>
map) throws
>>>>>>>> SQLException
>>>>>>>>       {
>>>>>>>>               // Auto-generated method stub
>>>>>>>>               return null;
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       public int getBaseType() throws SQLException
>>>>>>>>       {
>>>>>>>>               // Auto-generated method stub
>>>>>>>>               return 0;
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       public String getBaseTypeName() throws SQLException
>>>>>>>>       {
>>>>>>>>               // Auto-generated method stub
>>>>>>>>               return null;
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       public ResultSet getResultSet() throws SQLException
>>>>>>>>       {
>>>>>>>>               // Auto-generated method stub
>>>>>>>>               return null;
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       public ResultSet getResultSet(long index, int count)
throws
>>>>>>>> SQLException
>>>>>>>>       {
>>>>>>>>               // Auto-generated method stub
>>>>>>>>               return null;
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       public ResultSet getResultSet(long index, int count,
>>>>>>>> Map<String,
>>>>>>>> Class<
>>>>>>>> ? >> map) throws SQLException
>>>>>>>>       {
>>>>>>>>               // Auto-generated method stub
>>>>>>>>               return null;
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       public ResultSet getResultSet(Map<String, Class<
? >> map)
>>>>>>>> throws
>>>>>>>> SQLException
>>>>>>>>       {
>>>>>>>>               // Auto-generated method stub
>>>>>>>>               return null;
>>>>>>>>       }
>>>>>>>> }
>>>>>>>>
>>>>>>>> 2nd: implementation of java.sql.Array for use with int[]
or
>>>>>>>> Collection<Integer>
>>>>>>>>
>>>>>>>> public class IntArray
>>>>>>>> extends SqlArrayAdapter
>>>>>>>> {
>>>>>>>>       private static final Integer[] emptyArray = new Integer[0];
>>>>>>>>
>>>>>>>>       private int[] array;
>>>>>>>>
>>>>>>>>       public IntArray(int[] array)
>>>>>>>>       {
>>>>>>>>               if (array == null)
>>>>>>>>               {
>>>>>>>>                       throw new IllegalArgumentException("parameter
>>>>>>>> array
>>>>>>>> should not be
>>>>>>>> null");
>>>>>>>>               }
>>>>>>>>               this.array = array;
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       public IntArray(Collection<Integer> set)
>>>>>>>>       {
>>>>>>>>               if (set == null)
>>>>>>>>               {
>>>>>>>>                       throw new IllegalArgumentException("parameter
>>>>>>>> set
>>>>>>>> should not be null");
>>>>>>>>               }
>>>>>>>>               Integer[] keys = set.toArray(emptyArray);
>>>>>>>>
>>>>>>>>               this.array = new int[keys.length];
>>>>>>>>               for (int i = 0; i < keys.length; ++i)
>>>>>>>>               {
>>>>>>>>                       Integer key = keys[i];
>>>>>>>>                       this.array[i] = key.intValue();
>>>>>>>>               }
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       @Override
>>>>>>>>       public int getBaseType()
>>>>>>>> //    throws SQLException
>>>>>>>>       {
>>>>>>>>               return Types.INTEGER;
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       /**
>>>>>>>>        * This method is called by driver ver. 8 but not by
ver. 7.
>>>>>>>>        */
>>>>>>>>       @Override
>>>>>>>>       public String getBaseTypeName()
>>>>>>>> //    throws SQLException
>>>>>>>>       {
>>>>>>>>               return "int4";
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       /**
>>>>>>>>        * This method is called by both drivers ver. 8 and
7.
>>>>>>>>        */
>>>>>>>>       @Override
>>>>>>>>       public String toString()
>>>>>>>>       {
>>>>>>>>               String result = "{";
>>>>>>>>               for (int i = 0; i < this.array.length; ++i)
>>>>>>>>               {
>>>>>>>>                       if (i > 0)
>>>>>>>>                       {
>>>>>>>>                               result += ",";
>>>>>>>>                       }
>>>>>>>>                       result += this.array[i];
>>>>>>>>               }
>>>>>>>>               result += "}";
>>>>>>>>               return result;
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       public void free()
>>>>>>>> //    throws SQLException
>>>>>>>>       {
>>>>>>>>               this.array = null;
>>>>>>>>       }
>>>>>>>> }
>>>>>>>>
>>>>>>>> 3rd: implementation of TypeHandlerCallback
>>>>>>>>
>>>>>>>> public class IntArrayTypeHandler
>>>>>>>> implements TypeHandlerCallback
>>>>>>>> {
>>>>>>>>       public void setParameter(ParameterSetter setter, Object
>>>>>>>> parameter)
>>>>>>>>       throws SQLException
>>>>>>>>       {
>>>>>>>>               Collection<Integer> keys = (Collection<Integer>)
>>>>>>>> parameter;
>>>>>>>>               IntArray intArray = new IntArray(keys);
>>>>>>>>               setter.setArray(intArray);
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       public Object getResult(ResultGetter getter)
>>>>>>>>       throws SQLException
>>>>>>>>       {
>>>>>>>>               Array array = getter.getArray();
>>>>>>>>               return array;
>>>>>>>>       }
>>>>>>>>
>>>>>>>>       public Object valueOf(String string)
>>>>>>>>       {
>>>>>>>>               return string;
>>>>>>>>       }
>>>>>>>> }
>>>>>>>>
>>>>>>>> 4th: add the type handler to your configuration
>>>>>>>>       <typeAlias alias="IntArrayTypeHandler"
>>>>>>>> type="com.asci.common.ibatis.IntArrayTypeHandler" />
>>>>>>>>
>>>>>>>> 5th: SQL map
>>>>>>>>
>>>>>>>> <select id="selectFahrgastById" parameterClass="map"
>>>>>>>> resultMap="...">
>>>>>>>>       SELECT
>>>>>>>>               k.id,
>>>>>>>>               ...
>>>>>>>>       FROM kunden AS k
>>>>>>>>       WHERE k.id = ANY (#fahrgastIds,handler=IntArrayTypehandler#)
>>>>>>>> </select>
>>>>>>>>
>>>>>>>> 6th: DAO
>>>>>>>>
>>>>>>>> public List<Fahrgast> selectFahrgastById(Set<Integer>
fahrgastIds)
>>>>>>>> {
>>>>>>>>       HashMap<String, Object> params = new HashMap<String,
>>>>>>>> Object>();
>>>>>>>>       params.put("fahrgastIds", fahrgastIds);
>>>>>>>>       List<Fahrgast> list = getSqlMapClientTemplate().queryForList(
>>>>>>>>               "datenerfassung.selectFahrgastById", params);
>>>>>>>>       return list;
>>>>>>>> }
>>>>>>>>
>>>>>>>> jishnu123 schrieb:
>>>>>>>>>    Hai,
>>>>>>>>>
>>>>>>>>>          I have to tried insertion of array feild in
postgres
>>>>>>>>> database
>>>>>>>>> using
>>>>>>>>> spring mvc with iBatis.I got two lines error ...like
>>>>>>>>>
>>>>>>>>>                                 Error as follows...
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
-
>>>>>>>>> <Loading
>>>>>>>>> XML bean definitions from class path resource
>>>>>>>>> [org/springframework/jdbc/support/sql-error-codes.xml]>
>>>>>>>>>  [org.springframework.jdbc.support.SQLErrorCodesFactory]
-
>>>>>>>>> <SQLErrorCodes
>>>>>>>>> loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL,
Oracle,
>>>>>>>>> PostgreSQL,
>>>>>>>>> Sybase]>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>    Its urgent ....Please help me........Any one has an
idea 
>>>>>>>>> please
>>>>>>>>> reply
>>>>>>>>> immediately otherwise sent to my emaild id rjishnu@gmail.com
>>>>>>>>>
>>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>>>>>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>> --
>>>>>>> View this message in context:
>>>>>>> http://www.nabble.com/IBatis-Array-feild-insertion-problem-in-postgres-database%28%29Please-help-me%29-tp25799490p25815639.html
>>>>>>> Sent from the iBATIS - User - Java mailing list archive at
>>>>>>> Nabble.com.
>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>>>>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>>>>> The information contained in this e-mail is private & confidential
>>>>>>> and
>>>>>>> may
>>>>>>> also be legally privileged. If you are not the intended recipient,
>>>>>>> please
>>>>>>> notify us, preferably by e-mail, and do not read, copy or disclose
>>>>>>> the
>>>>>>> contents of this message to anyone.
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>>>>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>>>>>
>>>>>>>
>>>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>>>
>>>>>
>>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>>
>>>
>>>
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/IBatis-Array-feild-insertion-problem-in-postgres-database%28%29Please-help-me%29-tp25799490p26057542.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Mime
View raw message