By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,610 Members | 2,310 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,610 IT Pros & Developers. It's quick & easy.

Problem in Insertion

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.