Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 4th, 2005, 04:54 AM
Authorized User
 
Join Date: Oct 2004
Location: , , .
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


Reply With Quote
  #2 (permalink)  
Old March 4th, 2005, 12:50 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To add your number use a string, something like this:

int t1 = 10;
int t2 = 11;

String test = "" + t1 + t2;

The value of test will now be 1011.

As for the percentages do something like using your parameters instead of literal values.

 float debit = 0;
 float credit = 150;
 float pct = 10;

 debit = credit/100 * pct;



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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 Pro JSP 0 March 4th, 2005 04:56 AM
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



All times are GMT -4. The time now is 02:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.