Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;

public class Main {
    private static String escapeSql(String value) {
        if (value == null) {
            return "NULL";
        }
        String hexValue;
        try {
            hexValue = String.format("%x", new BigInteger(1, value.getBytes("UTF-8"))); // NOTE: implicitly assuming here database is using UTF-8 encoding
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Unsupported character");
        }
        return "X'" + hexValue + "'";
    }
}