File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "taking 7 digits from database" Watch "taking 7 digits from database" New topic

taking 7 digits from database

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
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 can i do this?using substring?please help me to do this.

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 is working.
[ May 28, 2008: Message edited by: preethi Ayyappan ]
Ilja Preuss

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.

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

Joined: Oct 27, 2005
Posts: 20188

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

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: taking 7 digits from database
It's not a secret anymore!