Archive for July, 2008

Convert Text To UniCode

Tuesday, July 1st, 2008 Posted in Java | Comments Off

private static String convertToUniCode(String inputString) throws Exception { String uniCodeString = ""; String prefix = "\\u"; String unicodebyte = new String(inputString.getBytes("UTF-8"),"UTF-8"); char[] charArray = unicodebyte.toCharArray(); StringBuffer sb = new StringBuffer(); for(int i=0; i<charArray.length; i++) { //System.out.print("\\u"+Integer.toHexString(charArray[i])); String ... Read more..

Database Connection and SQL Query

Tuesday, July 1st, 2008 Posted in Java | Comments Off

import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class DbUtils { public static void main(String[] args) { try { executeQuery("select * from persons"); } catch (Exception e) { e.printStackTrace(); } } public static void executeQuery(String sql) throws Exception { Connection conn ... Read more..

Image Processing

Tuesday, July 1st, 2008 Posted in Java | Comments Off

import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io.File; import java.math.BigDecimal; import javax.imageio.ImageIO; public class ImageTest01 { public static void main(String[] args) { BufferedImage img = loadImage("C:\\_Temp\\duke-real.gif"); float w = img.getWidth(); float h = img.getHeight(); System.out.println("w = " + w + ", ... Read more..

Load Object Bytes from a URL

Tuesday, July 1st, 2008 Posted in Java | Comments Off

private static byte[] loadFromURL(URL url) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream is = url.openStream(); int r; byte[] buffer = ... Read more..

Cursor Management

Tuesday, July 1st, 2008 Posted in SQL | Comments Off

DECLARE @Person char(50) DECLARE @FirstName VARCHAR(50) DECLARE c1 CURSOR FOR select Person, FirstName from Person OPEN c1 FETCH NEXT FROM c1 INTO @Person,@FirstName WHILE @@FETCH_STATUS = 0 BEGIN PRINT @Person + @FirstName FETCH NEXT FROM c1 INTO @Person, @FirstName ... Read more..

Example Database Schema : PetStore

Tuesday, July 1st, 2008 Posted in SQL | Comments Off

CREATE DATABASE mypetstore; USE mypetstore; CREATE TABLE IF NOT EXISTS supplier ( suppid int NOT NULL, name varchar(80) null, status varchar(2) not null, ... Read more..

Microsoft SQL Server Settings

Tuesday, July 1st, 2008 Posted in SQL | Comments Off

Collation SQL_Latin_General_CP1_C1_AS Recovery model Simple Compatibility level SQL Server 2005 (90) Automatic --------- Auto Close False Auto Create Stats True Auto Shrink False Auto Update Stats True Auto Update Stats Asynch False Cursor ------- Close Cursor on Commit Enabled False Default Cursor GLOBAL Misc ------ ANSI NULL Default False ANSI False Parameterization Simple ...... False ...... False Recovery ------- Page Verify CHECKSUM State ----- Database Read-Only False Restrict Access MULTI_USER Read more..

Example Database Schema: Typical WebSite

Tuesday, July 1st, 2008 Posted in SQL | Comments Off

CREATE TABLE [dbo].[Users]( [UserId] [int] IDENTITY(100,1) NOT NULL, [ContactId] [int] NOT NULL, [RoleId] [int] NOT NULL, [LoginId] [char](32) NOT NULL, [Password] [char](64) ); CREATE TABLE [dbo].[Roles]( [RoleId] [int] IDENTITY(100,1) NOT NULL, [Name] [char](32) NOT NULL, [Description] [char](256) NOT NULL, ); CREATE ... Read more..

Parse XML into MessageElement

Tuesday, July 1st, 2008 Posted in Java | Comments Off

import java.io.StringReader; import java.util.Iterator; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.axis.message.MessageElement; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; public class XmlTest { public static void main(String[] args) { try { MessageElement[] m = new MessageElement[1]; String xmlString = "<Results>" + "<Adjustments>" + "<Adjustment>" + "<RebuildAdjustmentID>16</RebuildAdjustmentID>" + "<IsBasicAdjustment>true</IsBasicAdjustment>" + "<AdjustmentType>stone</AdjustmentType>" + "<Title>External ... Read more..