devxlogo

Tip Bank

Count the Number of Occurrences of a String Within a String

The select statement below takes the name “george” and finds how many occurrences of “ge” appear within it. select (length(‘george’) – length (replace(‘george’,’ge’,”))) / length(‘ge’) countfrom dual/ COUNT———- 2 Using

Look Up a DataSource Object in Your Web Server

This code demonstrates how to look up a DataSource object in your Web server using JNDI Lookup. import javax.sql.DataSource;import java.util.Hashtable;import javax.naming.InitialContext;public void findDatasource() { // Initializing DataSource object DataSource dataSource

Sort a Collection of Objects

Suppose you have objects of type MyClass. Further assume that you have a collection (named myCollection) containing objects of type MyClass. To sort this collection, follow these steps: MyClass must

Track Process Runtime for Perl Scripts

For any script that takes more than just a few seconds to run, it’s always a good idea to track the runtime itself. This is especially useful in the development

How to Use an XPath on a DataSet

This small snippet shows how to use a XPath on a DataSet. Here are the used classes: DataRowDataSetXmlDataDocumentXmlNodeListXmlNode Here’s the XML file: One Three Four Two Finally, here’s the code: