Java Development
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Remember me

Go Back   Dev Articles Community ForumsProgrammingJava Development

Add This Thread To:   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
Unread Dev Articles Community Forums Sponsor:
Old March 21st, 2014, 08:29 AM
Nyra Nyra is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
Join Date: Mar 2014
Posts: 1 Nyra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 6 sec
Reputation Power: 0
Getting first Letter of Strings and insert them in Access

I'm new to this forum.

I am trying to get the first letter from two strings (Firstname and Lastname) and insert them into an access database.

Now the problem is not to get the first letters but to insert them into the database while inserting a new row as I have a field in the database named "User" in which i try to insert the first letters plus the automated ID from another field (STU_ID).. The thing is that the autogenerated Id in access is just created after i inserted the new row so i cant get the ID before... But when i try to get it afterwards the current row is the first in the recordset and i get the first letters of the last record plus the ID from the first record saved into the first records User field...

Any idea how i could achieve this (if someone understand)?

here my current code:
String first = txtFName.getText( );             
String last = txtLName.getText( );             
int eng = Integer.parseInt(txtEng.getText());             
int mat = Integer.parseInt(txtMat.getText());             
int phy = Integer.parseInt(txtPhy.getText());             
int geo = Integer.parseInt(txtGeo.getText());             
String name = lblName.getText();             
Date newdate = new Date();             
java.sql.Date sqldate = new java.sql.Date(newdate.getTime());             
String firstLetterFN = first.substring(0, 1);             
String firstLetterLN = last.substring(0, 1);      
jLabel8.setText(firstLetterFN + FirstLetterLN);    
try {
rs.updateString( "FName", first );                 
rs.updateString( "lName", last );                 
rs.updateInt( "English", eng );                 
rs.updateInt( "Mathematics", mat);                 
rs.updateInt( "Physics", phy);                 
rs.updateInt( "Geography", geo);                 
rs.updateDate( "Last Modified", sqldate);  
rs.updateString( "Modified by", name);
int id2 = rs.getInt("STU_ID");                             
String user = firstLetterFN + firstLetterLN + "_" + "S" + id2;       
rs.updateString("User", user);                    

Thanks in advance..

//Edit: Ok I tried a few things and now I got it.
I just changed the rs.moveToCurrentRow() to rs.last() and its working fine. Thansk anyway

Last edited by Nyra : March 21st, 2014 at 08:52 AM. Reason: Found answer myself

Reply With Quote

Viewing: Dev Articles Community ForumsProgrammingJava Development > Getting first Letter of Strings and insert them in Access

Developer Shed Advertisers and Affiliates

Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.

© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap