Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
|
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 4th, 2005, 04:56 AM
Authorized User
 
Join Date: Oct 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default automatic insertion of new record.....help......

i have done insertion of 6 field in the database..which is working good(code is below)...Now i want to do stuff that when i insert 6 field in database, then a new record also has to be insert into the database, in that new record the following changes should be done.

1)if i insert field code no ex.. 20 is inserted into the database then the a new code no 120 should be generated and inserted into database (the new code no should be started with 1, then the orginal code no will come) ex.. 10=101, 11=111, 256=1256,257=1257. The bold part is orginal record entered by the user, and the new record isnot bold.

2)Percentage field is there,ex 12%, 13% etc values will come , it calculates the percentage of credit amount field values and insert that values into the debit amount field of new record.

In my following code the code no is displayed as code, debit amount is shown as DrAmount, credit amount is shown as CrAmount, percentage field is shown as pct.


conn.setAutoCommit(false);

PreparedStatement pstmt = conn.prepareStatement("INSERT INTO gl_mast VALUES (?, ?, ?, ?, ?, ?)");

for (int i=1; request.getParameter((i==1)?"code":("code_" +i)) != null; i++){

String Code1=request.getParameter((i==1)?"code":("code_" +i));

int Code=Integer.parseInt(request.getParameter((i==1)? "code":("code_" +i)));
pstmt.setInt(1,Code);

String Description=request.getParameter((i==1)?"Descripti on":("Description_" +i));
pstmt.setString(2,Description);

float Dr_Amt =Float.parseFloat(request.getParameter((i==1)?"DrA mount":("DrAmount_" +i)));
pstmt.setFloat(3,Dr_Amt );

float Cr_Amt =Float.parseFloat(request.getParameter((i==1)?"CrA mount":("CrAmount_" +i)));
pstmt.setFloat(4,Cr_Amt);

String Type =request.getParameter((i==1)?"type":("type_" +i));
pstmt.setString(5,Type );

float Pct =Float.parseFloat(request.getParameter((i==1)?"pct ":("pct_" +i)));
pstmt.setFloat(6,Pct);

pstmt.addBatch();
conn.commit();
conn.setAutoCommit(true);

pstmt.executeBatch();



plz...look at my code and solved my prob....

thanx







Similar Threads
Thread Thread Starter Forum Replies Last Post
string insertion MunishBhatia ASP.NET 2.0 Professional 1 July 13th, 2007 08:20 AM
automatic insertion of new record.....help...... abhit_kumar JSP Basics 1 March 4th, 2005 12:50 PM
error while insertion... abhit_kumar JSP Basics 0 January 24th, 2005 09:09 AM
automatic record delete. joeore Beginning PHP 5 April 29th, 2004 11:27 AM
insertion sort..please amahja56 C++ Programming 1 March 1st, 2004 09:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.