August 22, 2006

Ping with J2SE 1.5.0

The following code shows you how to simulate the “ping” command with the J2SE Tiger InetAddress.isReachable method. import*;import*;public class reachable{ public static void main(String args[]) { String[] addrs= {“”,””,””}; try{ for(int i=0;i

Using the java.lang.reflect.Modifier Class

You know that you can extract constructors, methods, and variables from a Java class file. Generally, when you use Field fields[] = c.getDeclaredFields( ); where c is initialized using Class c = Class.forName(className); and print the fields array, you get all the elements declared in the class. However, suppose you

A Quick Way to Copy DataRow

Instead of copying DataRow column by column, the following code copies data in one line from the source to the destination row: DataTable dtDest = new DataTable();dtDest = dsActivity.Tables[0].Clone();foreach(DataRow dr in dsSrc.Tables[0].Rows){ DataRow newRow = dtDest .NewRow(); newRow.ItemArray = dr.ItemArray; dtDest.Rows.Add(newRow);} Note: The ImportRow method does the same thing, except

Retrieving a Single Value from a Database

This PHP function pulls a single field from a single record in the database once the MySQL connection has already been established: function getField($field, $tbl_name, $condition = 1){ $result = mysql_query(“SELECT $field FROM $tbl_name WHERE $condition”); return @mysql_result($result, 0);}$myValue = getField(“fieldName”,”myTable”,”id = ” . $uniqueID);

Read and Write Strings Using String Streams

String streams allow reading and writing strings just like cin and cout allow reading standard input and writing standard output. String streams may be used by including . Reading from a string is similar to reading input using cin: string s = “word 5”;istringstream iss(s);string w;int n;iss >> w >>

Nine ASP.NET Site Navigation Problem Solutions: Part 2

art one of this series introduced the first seven common site map navigation problems and their solutions. This part explores more advanced techniques with the final two problems: Hiding unauthorized pages. Including database-driven content in site map data. The solution to the first problem requires a brief review of ASP.NET