devxlogo

Tip Bank

Get the Keys for Rows Added by an INSERT Statement

This tip shows how to get the keys generated for the rows added by an INSERT statement. Statement st=null;PreparedStatement pst=null;Connection conn=null;ResultSet rs=null;ResultSetMetaData rsmd=null;…try { st= conn.createStatement(); }catch (SQLException e) {System.out.println(e.getMessage());}try

Workaround for the SQL DISTINCT Clause

The SQL DISTINCT clause isn’t case sensitive, which means that your query might end up pulling records with different cases. A simple fix for this is to use the COLLATE

Convert “Little-Endian” to “Big-Endian”

This tip outlines two simple methods that help you to convert a number from the “little-endian” format to the “big-endian” format. // 2-byte numberint SHORT_little_endian_TO_big_endian(int i){ return ((i>>8)&0xff)+((i

Returning a Random set of Records

The NEWID() function returns a uniqueidentifier for each row of data that is returned. Execute the following query in the AdventureWorks database: select top 5 productid, name from production.productorder by

Declare the Coolest XQuery Variables

Here’s how to declare some important variables in XQuery: declare variable $v as document-node(element(*,xdt:untyped)) external;: Use this variable to pass an XML tree to a XQuery query. declare namespace nameSpace=”http://nameSpace.org”;

Emitting a Beep in Java

There are three ways to emit a beep in Java: Use an AU audio file: In Java, AU files need to be created at a sample rate of 8000. Higher