dcsimg
How do i use jdbc to insert a value into a packed decimal field?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ken_persky
Posted On:   Tuesday, February 5, 2002 07:50 AM

I am trying to insert a record into a table on a as400 and I have encountered a problem dealing with packed decimal fields. I tried using the as400packeddecimal class from the as400 javatoolkit to create as such: PreparedStatement pstmt = conn.prepareStatement("insert into lib.table ?"); AS400packedDecimal blah = new AS400PackedDecimal(double mydouble); byte [] byteArray = blah.getBytes(); pstmt.setBytes(1, byteArray); In this senario the field is a packed decimal. I get a type mismatch when i run the query. So my question is how do I get a number into a packed decimal field on the as400 using jdbc?    More>>

I am trying to insert a record into a table on a as400 and I have encountered a problem dealing with packed decimal fields. I tried using the as400packeddecimal class from the as400 javatoolkit to create as such:



PreparedStatement pstmt = conn.prepareStatement("insert into lib.table ?");

AS400packedDecimal blah = new AS400PackedDecimal(double mydouble);

byte [] byteArray = blah.getBytes();

pstmt.setBytes(1, byteArray);



In this senario the field is a packed decimal. I get a type mismatch when i run the query. So my question is how do I get a number into a packed decimal field on the as400 using jdbc?

   <<Less

Re: How do i use jdbc to insert a value into a packed decimal field?

Posted By:   T_K  
Posted On:   Friday, February 22, 2002 12:12 PM

You don't have to use the BigDecimal object. Depending on what the scale of
the packed field is, you can just use int, long, float, or double. For example, you can insert a 5,0
packed field with pstmt.setInt(1, 12345) or you could insert a 7,2 packed
field with pstmt.setDouble(1, 12345.23).

Re: How do i use jdbc to insert a value into a packed decimal field?

Posted By:   noriaki_ishihara  
Posted On:   Wednesday, February 13, 2002 04:56 PM

I think you are mixing 2 different things here; JDBC and AS400 packages.

For JDBC, BigDecimal must be used in the place of packed decimal like following.

conn.setBigDecimal(1, new BigDecimal("3.0"));

Check the JTOpen's documentation, they have tons of examples.
About | Sitemap | Contact