473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem in Insertion

Hi,

When I tried inserting the value 0.01 to the table it is getting
inserted as 0.00. The column's data type is Decimal(10,2). I am doing
this insertion from my java program. I am not doing any formatting or
any other information. I am getting this data and inserting it into the
Db2 table.

Has anyone faced this problem.

Please write me a solution

-Suby

Nov 12 '05 #1
3 1097
suby wrote:
Hi,

When I tried inserting the value 0.01 to the table it is getting
inserted as 0.00. The column's data type is Decimal(10,2). I am doing
this insertion from my java program. I am not doing any formatting or
any other information. I am getting this data and inserting it into the
Db2 table.

Has anyone faced this problem.

Please write me a solution

-Suby

Post *YOUR* sample java code for review. Don't expect solutions.

I tested quickly from CLP and I do not see the issue you described:

D:\Working>db2 create table test (c1 decimal(10,2))
DB20000I The SQL command completed successfully.

D:\Working>db2 insert into test values(0.01)
DB20000I The SQL command completed successfully.

D:\Working>db2 select * from lazy_poster

C1
---------------
0.01

1 record(s) selected.
Jan M. Nelken
Nov 12 '05 #2
suby wrote:
Hi,

When I tried inserting the value 0.01 to the table it is getting
inserted as 0.00. The column's data type is Decimal(10,2). I am doing
this insertion from my java program. I am not doing any formatting or
any other information. I am getting this data and inserting it into the
Db2 table.

Has anyone faced this problem.

Please write me a solution

-Suby


Post *YOUR* sample java code for review. Don't expect solutions.

I tested quickly from CLP and I do not see the issue you described:

D:\Working>db2 create table test (c1 decimal(10,2))
DB20000I The SQL command completed successfully.

D:\Working>db2 insert into test values(0.01)
DB20000I The SQL command completed successfully.

D:\Working>db2 select * from test

C1
---------------
0.01

1 record(s) selected.
Jan M. Nelken
Nov 12 '05 #3
I am getting the value from a CSV file for insertion. there will be one
more method that check each & every column & set it to the
Transactiondata object.

below is the code.

public class DataExtract {

public static int y = 0;
public static void main(String[] args)
{
TransactionData trData;
DataExtract de = new DataExtract();
File f = new File("C:\\Subha\\SDS\\trans_20050611.csv");

Connection con = null;
PreparedStatement stmt = null;
Statement selSlotst = null;
ResultSet rs = null;
String sql = null;
StringBuffer strBuf = null;

try
{
Class.forName("com.ibm.db2.jcc.DB2Driver");
con =
DriverManager.getConnection("jdbc:db2://10.1.204.105:30000/sds","db2util","db2util");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String recRead = br.readLine();
StringTokenizer st = new StringTokenizer(recRead,",",false);
int tokenNum = st.countTokens();
int i = 0;

while((recRead = br.readLine()) != null && i<10)
{
trData = de.setTranValues(recRead);
i++;

//Inserting into slot master
strBuf = new StringBuffer();
strBuf.append("select count(sltm_id) from slot_master ");
strBuf.append("where sltm_status_code = " + trData.getSlotStatus()
+ " and ");
strBuf.append("area_id = " + trData.getAreaID() + " and ");
strBuf.append("sltm_slot_number = " + trData.getSlotNum() + " and
");
strBuf.append("sltm_stand = '" + trData.getStand() + "' and ");
strBuf.append("sltm_acct_denom = " + trData.getAcctDenom() + " and
");
strBuf.append("sltm_eprom_id = '" + trData.getEpromID() + "' and
");
strBuf.append("sltm_doc_id = '" + trData.getDocID() + "'");
int slotCount = 0;
selSlotst = con.createStatement();
rs = selSlotst.executeQuery(strBuf.toString());
if(rs.next())
{
slotCount = rs.getInt(1);
}
if(slotCount == 0)
{
sql = "Select max(sltm_id)+1 slotID from slot_master";

rs = selSlotst.executeQuery(sql);
int slotID = 0;
if(rs.next())
{
slotID = rs.getInt(1);
}
if(slotID == 0)
{
slotID++;
}

stmt = con.prepareStatement("INSERT INTO SLOT_MASTER
(sltm_id,sltm_status_code,area_id,sltm_slot_number , sltm_stand,
sltm_acct_denom, sltm_eprom_id, sltm_doc_id) VALUES(?,?,?,?,?,?,?,?)");

stmt.setInt(1,slotID);
stmt.setInt(2,trData.getSlotStatus());
stmt.setInt(3,trData.getAreaID());
stmt.setInt(4,trData.getSlotNum());
stmt.setString(5, trData.getStand());
System.out.println (trData.getAcctDenom());
stmt.setFloat(6,trData.getAcctDenom());
stmt.setString(7,trData.getEpromID());
stmt.setString(8,trData.getDocID());

stmt.execute();
}
}

}
catch(SQLException se)
{
se.printStackTrace();
System.out.println("SQL Exception " + se.getMessage());
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception " + e.getMessage());
}

}

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ronan | last post by:
Hi, I have a problem with a form using the PHP PEAR HTML_QuickForm package & javascript: I want to record the content of my form into a mySQL database then execute a javascript function. ...
4
by: Helene Pinol | last post by:
Dear All I have a problem to insert elements in a combination of containers. Here is the declaration of the container I would like to use: vector< set<myElement> >...
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
0
by: Lyn | last post by:
I am having a frustrating time trying to do a simple insert of a BMP picture into a Bound Object Frame using both VBA and the Insert | Object... dialog. I had a separate post thread going on this...
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
0
by: mharris | last post by:
I need help with merging two Word documents into one through C# code. The problem isn't so much getting the documents put into one as it is maintaining the appropriate formatting, or rather...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
4
by: Andrix | last post by:
Hi, I have a table with 20.000.000 of tuples. I have been monitoring the performance of the insertion and updates, but not convince me at all. The table have 30 columns, what and 12 of it, are...
3
by: Franco Perilli | last post by:
I've compiled this code and no problems, but when I run the program, it prints only the last entry i've inserted. Looks like a problem in the sorted insertion algorithm. Can u help me plz? ...
4
by: Gaijinco | last post by:
I'm doing a template class to make an ordered list. I created a class Person to make an agenda. When I create a new person, there's no problem but when I try to add it to the list it throws a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.