This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes DB query with prefix Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "DB query with prefix" Watch "DB query with prefix" New topic
Author

DB query with prefix

manu chaox
Ranch Hand

Joined: Apr 10, 2006
Posts: 110
Hi,
could you help me.

I have DB table tab with column (id, number).
The column number means number of star(*), which is display before every row(DB record).
I'd like to display result of DB query(select * from tab) in this way:
(I used JDBC connection.)

1,0
*2,1
***3,3
**4,2
...

Could you help to beginner.
Thanks
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

See if the function LPAD works for you.

Kaydell
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

Quoting from a private message from manu chao:
I'd like to java solution, not DB solution.


Here's how you can pad the left side of a String with a given number of asterisks in Java:

1. You can create a StringBuffer object that is initially empty.
2. Calculate the number of astericks to append. number - string.length()
3. Append the asterisks to the StringBuffer object
4. Append the original String object to the StringBuffer object
5. Convert the StringBuffer to a String with: sb.toString()

I'll leave it up to you to convert this to actual Java code.

Kaydell
[ July 12, 2007: Message edited by: Kaydell Leavitt ]
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: DB query with prefix
 
jQuery in Action, 3rd edition