*
The moose likes Beginning Java and the fly likes taking 7 digits from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "taking 7 digits from database" Watch "taking 7 digits from database" New topic
Author

taking 7 digits from database

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Hi,
I am storing a callerid number in a table.I need to get only the last 7 digits
from the callerid and i have to display it.for example if i am storing 043255667778.i have to get 5667778 and to display it.how can i do this?using substring?please help me to do this.

Thanks
amitabh mehra
Ranch Hand

Joined: Dec 05, 2006
Posts: 98
From what I understood from your description is that you are storing a caller id in some database table as a varchar. And later, after retrieving you want to display the last 7 digits using substring function.

If this is correct then you can try: (assuming you fetched the string in str variable of type string)

String lastSeven = str.substring(str.length() - 7);
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
thanks.it is working.
[ May 28, 2008: Message edited by: preethi Ayyappan ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Alternatively, you could do this directly in SQL. Depending on the number of records you are retrieving, this might reduce the network bandwidth consumed by the database query.

http://www.1keydata.com/sql/sql-substring.html


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

MS SQL (and perhaps others) also have methods called LEFT and RIGHT. Perhaps you can use those too:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: taking 7 digits from database
 
Similar Threads
how to pass value one program to another program
JSP Error
Getting error
how to set and get a value
to get callerid through jdbc