Popular Posts
Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... Word break tag : <wbr/> (HTML5) The  HTML  <wbr>  tag  is  used  defines  a  potential  line  break  point  if  needed.  This  stands  for  Word  BReak. This  is  u... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i...
Blog Archive
Stats
List remote share folder
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class Class1
    {
        #region Get remote share folder name, use Windows API NetShareEnum
        [DllImport("Netapi32.dll", CharSet = CharSet.Unicode)]
        private static extern NET_API_STATUS NetShareEnum(
             StringBuilder serverName,
             int level,
             ref IntPtr bufPtr,
             uint prefMaxLen,
             ref int entriesRead,
             ref int totalEntries,
             ref int resumeHandle
             );

        [DllImport("Netapi32.dll", SetLastError = true)]
        static extern int NetApiBufferFree(IntPtr Buffer);

        public enum NET_API_STATUS : uint
        {
            NERR_Success = 0,
            NERR_InvalidComputer = 2351,
            NERR_NotPrimary = 2226,
            NERR_SpeGroupOp = 2234,
            NERR_LastAdmin = 2452,
            NERR_BadPassword = 2203,
            NERR_PasswordTooShort = 2245,
            NERR_UserNotFound = 2221,
            ERROR_ACCESS_DENIED = 5,
            ERROR_NOT_ENOUGH_MEMORY = 8,
            ERROR_INVALID_PARAMETER = 87,
            ERROR_INVALID_NAME = 123,
            ERROR_INVALID_LEVEL = 124,
            ERROR_MORE_DATA = 234,
            ERROR_SESSION_CREDENTIAL_CONFLICT = 1219
        }

        [StructLayoutAttribute(LayoutKind.Sequential)]
        public struct _SHARE_INFO_0
        {
            [MarshalAsAttribute(UnmanagedType.LPWStr)]
            public string shi0_netname;
        }

        public static void EnumNetShares(string remoteMachineName)
        {
            StringBuilder serverName = new StringBuilder(remoteMachineName);
            int level = 0;
            IntPtr bufPtr = IntPtr.Zero;
            uint prefMaxLen = 0xFFFFFFFF;
            int entriesRead = 0;
            int totalEntries = 0;
            int resumeHandle = 0;
            int structSize = Marshal.SizeOf(typeof(_SHARE_INFO_0));

            NET_API_STATUS result = NetShareEnum(serverName, level, ref bufPtr, prefMaxLen, ref entriesRead, ref totalEntries, ref resumeHandle);
            if (result == NET_API_STATUS.NERR_Success)
            {
                IntPtr current = bufPtr;
                for (int i = 0; i < entriesRead; i++)
                {
                    _SHARE_INFO_0 shareInfo = (_SHARE_INFO_0)Marshal.PtrToStructure(current, typeof(_SHARE_INFO_0));
                    Console.WriteLine(shareInfo.shi0_netname);
                    current = new IntPtr(current.ToInt32() + structSize);
                }
            }
            else if (result == NET_API_STATUS.ERROR_MORE_DATA)
            {
                NetApiBufferFree(bufPtr);
            }
            else
            {
                // Something else.
            }
        }
        #endregion

        #region Get remote share folder name, use WMI
        private static void DisplayShareFolders(string computerName, string userName, string password)
        {
            string queryStr = "select * from Win32_Share";

            ConnectionOptions co = new ConnectionOptions();
            co.Username = userName;
            co.Password = password;

            ManagementScope ms = new ManagementScope(string.Format(@"\\{0}\root\cimv2", computerName), co);
            ms.Connect();
            if (ms.IsConnected)
            {
                ObjectQuery query = new ObjectQuery(queryStr);
                using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(ms, query))
                {
                    using (ManagementObjectCollection searchResult = searcher.Get())
                    {
                        foreach (ManagementObject mo in searchResult)
                        {
                            foreach (PropertyData property in mo.Properties)
                            {
                                Console.WriteLine("Name:{0}\tPath:{1}", mo.Properties["Name"].Value.ToString(), mo.Properties["Path"].Value.ToString());
                            }
                        }
                    }
                }
            }
        }
        #endregion
    }
}
RETURNING : return value from query
SET SERVEROUTPUT ON;
DECLARE 
    v_column VARCHAR2(100);
BEGIN
    DBMS_OUTPUT.ENABLE;
    INSERT INTO table1(column1) VALUES ('TEST VALUE') RETURNING column1 INTO v_column;
    DBMS_OUTPUT.PUT_LINE(v_column);
END;
EXECUTE IMMEDIATE : execute string query
SET SERVEROUTPUT ON;

/* execute query */
DECLARE
BEGIN
    EXECUTE IMMEDIATE 'SELECT CURRENT_DATE FROM DUAL';
END;

/* execute query & set value */
DECLARE
    v_time DATE;
BEGIN
    DBMS_OUTPUT.ENABLE;
    EXECUTE IMMEDIATE 'SELECT CURRENT_DATE FROM DUAL' INTO v_time;
    DBMS_OUTPUT.PUT_LINE(v_time);
END;

/* execute query with parameter */
DECLARE
    v_emp_id VARCHAR2(20);
    v_name VARCHAR2(20);
BEGIN
    v_name := 'Bruce';
    v_emp_id := '00987';
    EXECUTE IMMEDIATE 'UPDATE employee SET employee_name = :1 WHERE employee_id = :2'
    USING v_name, v_emp_id;
    COMMIT;
END;

/* execute procedure */
DECLARE
    v_start_index NUMBER := 24;
    v_end_index NUMBER:= 587;
    v_sum NUMBER;
    v_status NUMBER(1,0);
BEGIN
    DBMS_OUTPUT.ENABLE;
    EXECUTE IMMEDIATE 'BEGIN get_lot_amount(:1, :2, :3); END;'
    USING IN v_start_index, IN v_end_index, OUT v_sum, IN OUT v_status;

    IF v_status = 0 THEN
        DBMS_OUTPUT.PUT_LINE('ERROR');
    END IF;
END;
Memorize xml document operation
I have not write codes about operating xml document by C# for months. Almost forget all...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using Sportingbet.net;
using Sportingbet.util;
using System.Xml.Linq;
using System.Xml.XPath;
using System.Xml;

class Program
{
    static void Main(string[] args)
    {
        string xml = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "tmp.xml");
        XDocument xDoc = XDocument.Parse(xml);
        var nodes = from e in xDoc.XPathSelectElements("//myTag")
                    select e;
        foreach (var e in nodes)
        {
            Console.WriteLine(e);
        }

        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(xml);
        XmlNodeList nodelist = xmlDoc.SelectNodes("//myTag");
        foreach (XmlNode e in nodelist)
        {
            Console.WriteLine(e.OuterXml);
        }
    }
}
Clone any object
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

import bruce.lib.swing.JTextBox;

public class CloneObject {

    public static Object clone(Object source) {
        Object newObject = new Object();
        ObjectOutputStream ooStr = null;
        try {
            ByteArrayOutputStream baoStr = new ByteArrayOutputStream();
            ooStr = new ObjectOutputStream(baoStr);
            ooStr.writeObject(source);
            ooStr.flush();
            ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(baoStr.toByteArray()));
            newObject = in.readObject();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(CloneObject.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(CloneObject.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                ooStr.close();
            } catch (IOException ex) {
                Logger.getLogger(CloneObject.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return newObject;

    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        JTextBox textbox = new JTextBox("A simple textbox", 20);
        System.out.printf("Hashcode : %d%n", textbox.hashCode());

        JTextBox clonedTextBox = (JTextBox) clone(textbox);
        System.out.printf("Cloned hashcode : %d%n", clonedTextBox.hashCode());
        System.out.printf("Cloned text : %s%n", clonedTextBox.getText());

    }

}
Print multiple image
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

public class PringMultipleImage implements Printable {

    @Override
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
        // 要列印的圖片
        BufferedImage[] images = this.getPrintImages();
        if (images.length == 0)
            return Printable.NO_SUCH_PAGE;

        // 固定寬度(以符合掃描器大小)
        double stickerWidth = 220;
        double maxStickerHeight = 0; // 最大高度
        for (int i = 0; i < images.length; i++) {
            maxStickerHeight = Math.max(maxStickerHeight, stickerWidth / images[i].getWidth() * images[i].getHeight());
        }
        // 計算頁面可列印張數, 每頁張數 : c*r
        int c = (int) (pageFormat.getImageableWidth() / stickerWidth);
        int r = (int) (pageFormat.getImageableHeight() / maxStickerHeight);
        int p = (int) Math.ceil(1.0 * images.length / c / r); // 頁數

        if (pageIndex < p) {
            // 計算cell大小
            double cellWidth = pageFormat.getImageableWidth() / c;
            double cellHeight = pageFormat.getImageableHeight() / r;
            // 計算位置
            double translateX = (cellWidth - stickerWidth) / 2;

            // 
            int cellx = 0;
            int celly = 0;

            for (int i = 0 + pageIndex * c * r; i < images.length; i++) {
                double stickerHeight = stickerWidth / images[i].getWidth() * images[i].getHeight();
                double translateY = (cellHeight - stickerHeight) / 2;

                graphics.drawImage(images[i], //
                        (int) (translateX + cellx * cellWidth), //
                        (int) (translateY + celly * cellHeight), //
                        (int) stickerWidth, //
                        (int) stickerHeight, //
                        null);

                // 下一個cell
                if (cellx + 1 == c) {
                    cellx = 0;
                    celly++;
                } else {
                    cellx++;
                }
            }
            return Printable.PAGE_EXISTS;
        } else {
            return Printable.NO_SUCH_PAGE;
        }
    }

    private BufferedImage[] getPrintImages() {
        // Generate image here
        return null;
    }

    public static void main(String[] args) {
        PrinterJob job = PrinterJob.getPrinterJob();
        job.setPrintable(new PringMultipleImage());
        if (job.printDialog()) {
            try {
                job.print();
            } catch (PrinterException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
reference:
Lesson: Printing (The Java™ Tutorials > 2D Graphics)
Java Print Service API User Guide
Convert swing component to image
package y11.m03;

import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextField;

public class PrintTester {

    public static void main(String[] args) throws IOException {
        JPanel p = new JPanel(new GridLayout(2, 2));
        p.add(new JTextField("wwww", 20));
        p.add(new JLabel("dfdfdf"));
        p.add(new JSpinner());
        p.add(new JButton("fdfdf"));

        BufferedImage image = createImage(p);
        ImageIO.write(image, "png", new File("PrintTest2.png"));
    }

    // if component is rendered
    public static BufferedImage createImage(JComponent component) {
        int w = component.getWidth();
        int h = component.getHeight();
        BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = img.createGraphics();
        component.paint(g);
        return img;
    }

    // if component is not rendered
    public static BufferedImage createImage(JComponent component, AffineTransform transform) throws IOException, ClassNotFoundException {
        if (component == null)
            return null;
        JFrame f = new JFrame(); // for paint
        JComponent clone = (JComponent) clone(component);
        f.add(clone);
        f.pack();

        BufferedImage image = new BufferedImage(clone.getWidth(), clone.getHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = image.createGraphics();
        if (transform != null)
            g.setTransform(transform);
        clone.paint(g);
        f.dispose();
        return image;
    }

    public static <T extends Serializable> T clone(T source) throws IOException, ClassNotFoundException {
        Object newObject = new Object();
        ObjectOutputStream ooStr = null;
        ByteArrayOutputStream baoStr = new ByteArrayOutputStream();
        ooStr = new ObjectOutputStream(baoStr);
        ooStr.writeObject(source);
        ooStr.flush();
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(baoStr.toByteArray()));
        newObject = in.readObject();
        ooStr.close();
        return (T) newObject;
    }
}
DownloadProcess
ProxyConfig.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class ProxyConfig
{
    public static ProxyConfig DefaultProxy;

    public string Host { get; set; }
    public int Port { get; set; }
    public string Account { get; set; }
    public string Password { get; set; }

    public ProxyConfig(string host, int port, string account, string password)
    {
        this.Host = host;
        this.Port = port;
        this.Account = account;
        this.Password = password;
    }
}
DownloadProcess.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Threading;
using System.Text.RegularExpressions;

public class DownloadProcess
{
    public static string GetHtmlSource(string url, ProxyConfig proxy)
    {
        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
        // 設置代理伺服器
        if (proxy != null)
        {
            WebProxy p = new WebProxy(proxy.Host, proxy.Port);
            p.Credentials = new NetworkCredential(proxy.Account, proxy.Password);
            request.Proxy = p;
        }

        HttpWebResponse response = request.GetResponse() as HttpWebResponse;
        Stream s = response.GetResponseStream();
        StreamReader reader = new StreamReader(s);
        string source = reader.ReadToEnd();
        reader.Close();
        s.Close();
        response.Close();

        return source;
    }

    /// <summary>
    /// 目標網址
    /// </summary>
    public string Url { get; set; }
    /// <summary>
    /// 儲存的目錄位置
    /// </summary>
    public string StorePath { get; set; }
    /// <summary>
    /// 儲存的檔名 (Optional)
    /// </summary>
    public string StoreFilename
    {
        get { return this._StoreFilename; }
        set
        {
            this._IsFilenameCustomized = true;
            this._StoreFilename = value;
        }
    }
    /// <summary>
    /// 代理伺服器設定
    /// </summary>
    public ProxyConfig Proxy { get; set; }
    /// <summary>
    /// 串流(資料)長度
    /// </summary>
    public long Length { get; private set; }
    /// <summary>
    /// 已收到的串流(資料)長度
    /// </summary>
    public long AcceptedLength { get; private set; }
    /// <summary>
    /// 開始下載時間
    /// </summary>
    public DateTime BeginTime { get; private set; }
    /// <summary>
    /// 完成下載時間
    /// </summary>
    public DateTime EndTime { get; private set; }
    /// <summary>
    /// 處理完成
    /// </summary>
    public bool IsCompleted { get; private set; }

    /// <summary>
    /// 儲存檔名
    /// </summary>
    private string _StoreFilename;
    /// <summary>
    /// 自訂儲存檔名
    /// </summary>
    private bool _IsFilenameCustomized = false;
    /// <summary>
    /// 停止下載標記
    /// </summary>
    private bool _StopFlag = false;
    /// <summary>
    /// 讀取時的Buffer大小
    /// </summary>
    private int _ReadBuffer = 128;
    /// <summary>
    /// 寫入磁碟間隔(sec)
    /// </summary>
    private int _FlushInterval = 5;
    /// <summary>
    /// 執行寫入磁碟旗標
    /// </summary>
    private bool _IsFlushing = false;
    /// <summary>
    /// 記錄寫入磁碟時間
    /// </summary>
    private DateTime _LastFlushTime;

    public DownloadProcess()
    {
        this._LastFlushTime = DateTime.Now;
    }
    public DownloadProcess(string url, string storePath)
        : this()
    {
        this.Url = url;
        this.StorePath = storePath;
    }
    public DownloadProcess(string url, string storePath, ProxyConfig proxy)
        : this(url, storePath)
    {
        this.Proxy = proxy;
    }
    /// <summary>
    /// 開始下載
    /// </summary>
    public void Start()
    {
        new Thread(() =>
        {
            this.AcceptedLength = 0;
            this.IsCompleted = false;
            this.BeginTime = DateTime.Now;
            this.EndTime = DateTime.MinValue;

            // 解析檔名
            this.ParseFileName();

            HttpWebRequest request = WebRequest.Create(this.Url) as HttpWebRequest;
            // 設置代理伺服器
            if (this.Proxy != null)
            {
                WebProxy p = new WebProxy(this.Proxy.Host, this.Proxy.Port);
                p.Credentials = new NetworkCredential(this.Proxy.Account, this.Proxy.Password);
                request.Proxy = p;
            }
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            // 檢查附件名稱
            this.ParseAttachmentName(response);

            // 嘗試取得串流長度
            this.Length = response.ContentLength;

            // 讀取位元數
            int readed = 0;
            // Buffer
            byte[] buf = new byte[this._ReadBuffer];
            // 暫存資料
            MemoryStream ms = new MemoryStream();

            Stream stream = response.GetResponseStream();
            while ((readed = stream.Read(buf, 0, buf.Length)) > 0)
            {
                // 記錄接收的串流長度
                this.AcceptedLength += readed;
                // 寫入暫存
                ms.Write(buf, 0, readed);

                // 寫入磁碟
                if (!this._IsFlushing && DateTime.Now.AddSeconds(-1 * this._FlushInterval) > this._LastFlushTime)
                {
                    ms.Close();
                    this.FlushToDisk(ms.ToArray());
                    ms = new MemoryStream();
                }

                // 強迫中斷
                if (this._StopFlag) break;
            }

            stream.Close();
            ms.Close();
            // 等待未完成寫入作業
            while (this._IsFlushing)
            {
                Thread.Sleep(100);
            }
            this.FlushToDisk(ms.ToArray());
            this.EndTime = DateTime.Now;
            this.IsCompleted = true;
        }).Start();
    }
    /// <summary>
    /// 中斷下載
    /// </summary>
    public void Stop()
    {
        this._StopFlag = true;
    }
    /// <summary>
    /// 由輸入網址產生檔名
    /// </summary>
    private void ParseFileName()
    {
        if (!this._IsFilenameCustomized && !string.IsNullOrWhiteSpace(Url))
        {
            Uri url = new Uri(this.Url);
            this.StoreFilename = url.Segments[url.Segments.Length - 1];
        }
    }
    /// <summary>
    /// 檢查是否有附件名稱
    /// </summary>
    /// <param name="res"></param>
    private void ParseAttachmentName(HttpWebResponse res)
    {
        if (!string.IsNullOrWhiteSpace(res.Headers["Content-Disposition"]))
        {
            string filename = Regex.Match(
                res.Headers["Content-Disposition"],
                "filename=(.+)",
                RegexOptions.IgnoreCase
            ).Groups[1].Value;

            if (!string.IsNullOrWhiteSpace(filename))
            {
                this.StoreFilename = filename;
            }
        }
    }
    /// <summary>
    /// 將暫存資料寫入磁碟
    /// </summary>
    /// <param name="buffer"></param>
    private void FlushToDisk(byte[] buffer)
    {
        new Thread(() =>
        {
            // 標記為寫入中
            this._IsFlushing = true;
            FileStream fs = new FileStream(
                Path.Combine(this.StorePath, this.StoreFilename),
                FileMode.Append, FileAccess.Write, FileShare.Write
            );
            fs.Write(buffer, 0, buffer.Length);
            fs.Close();
            // 延遲
            Thread.Sleep(100);
            // 記錄寫入時間
            this._LastFlushTime = DateTime.Now;
            this._IsFlushing = false;
        }).Start();
    }
    /// <summary>
    /// 以適當單位顯示大小
    /// </summary>
    /// <param name="length">位元數</param>
    /// <param name="ext">單位</param>
    /// <returns></returns>
    private string toSize(double length, SizeExtension ext)
    {
        if (ext == SizeExtension.Byte && length < 1) return "0 Byte";
        if (ext == SizeExtension.GB) return string.Format("{0:00.00} {1}", length, ext);
        if (length < 1024)
        {
            return string.Format("{0:##.##} {1}", length, ext);
        }
        else
        {
            return toSize(length / 1024, (SizeExtension)(ext + 1));
        }
    }
    /// <summary>
    /// 串流(資料)長度
    /// </summary>
    /// <returns></returns>
    public string GetLength()
    {
        return this.toSize(this.Length, SizeExtension.Byte);
    }
    /// <summary>
    /// 已收到的串流(資料)長度
    /// </summary>
    /// <returns></returns>
    public string GetAcceptedLenght()
    {
        return this.toSize(this.AcceptedLength, SizeExtension.Byte);
    }
}
Java: ResultSet on store procedure
Oracle
CREATE OR REPLACE PROCEDURE get_result (
    start_pattern IN VARCHAR2,
    end_pattern IN VARCHAR2,
    result_set OUT SYS_REFCURSOR
) IS
BEGIN
    OPEN result_set FOR
        SELECT
            sheet_id
        FROM checksheet_with_process
        WHERE
            sheet_id >= start_pattern
            AND sheet_id <= end_pattern
        ORDER BY sheet_id DESC;

END;

-- test 
SET SERVEROUTPUT ON;
DECLARE
result_set SYS_REFCURSOR;
sheet_id VARCHAR2(50);
BEGIN
    DBMS_OUTPUT.ENABLE;
    get_sheet_print_list('20100923','20101023',result_set);
    
    LOOP
        FETCH result_set INTO
            sheet_id
        ;
        EXIT WHEN result_set%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(sheet_id);
    END LOOP;
END;
ProcedureResult.java
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ProcedureResult {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Connection conn = null;
        CallableStatement stmt = null;
        ResultSet rs = null;

        try {
            conn = DriverManager.getConnection("connection string");
            stmt = conn.prepareCall("CALL get_result(?,?,?)");
            stmt.setString(1, "20101001");
            stmt.setString(2, "20101031");
            stmt.registerOutParameter(3, oracle.jdbc.driver.OracleTypes.CURSOR);
            stmt.execute();
            rs = (ResultSet) stmt.getObject(3);

            while (rs != null && rs.next()) {
                System.out.println(rs.getString("sheet_id"));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (rs != null)
                try {
                    rs.close();
                } catch (SQLException e2) {
                    // TODO Auto-generated catch block
                    e2.printStackTrace();
                }
            if (stmt != null)
                try {
                    stmt.close();
                } catch (SQLException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            if (conn != null)
                try {
                    conn.close();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
        }
    }

}
Default checkbox renderer in JTabel
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class CheckBoxCellinTable extends JFrame {

    JTable table;

    public CheckBoxCellinTable() {

        this.setLayout(new BorderLayout());
        this.initTable();

        setSize(400, 300);
        Dimension sc = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((sc.width - getWidth()) / 2, (sc.height - getHeight()) / 2);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    void initTable() {
        Object[] columnNames = { "First Name", "Last Name", "Married" };
        Object[][] data = { { "Harry", "Smith", true }, { "Sally", "Jones", false }, { "Bob", "Clark", true }, { "Eric", "Burke", true } };

        DefaultTableModel model = new DefaultTableModel(data, columnNames) {
            @Override
            public boolean isCellEditable(int row, int column) {
                return column == 2;
            }

            @Override
            public Class<?> getColumnClass(int columnIndex) {
                return columnIndex == 2 ? Boolean.class : super.getColumnClass(columnIndex);
            }
        };
        table = new JTable(model);

        this.add(new JScrollPane(table), BorderLayout.CENTER);
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new CheckBoxCellinTable();
    }

}
Cursor with parameter
SET SERVEROUTPUT ON;
DECLARE 
    id_start VARCHAR2(200);
    CURSOR get_old_id(id_pattern VARCHAR2) IS
        SELECT
        column1
        FROM table1
        WHERE column1 LIKE id_pattern
        ORDER BY column1 ASC
    ;

BEGIN
    DBMS_OUTPUT.ENABLE;
    OPEN get_old_id('2010%');
    FETCH get_old_id INTO id_start;
    DBMS_OUTPUT.PUT_LINE(id_start);
    CLOSE get_old_id;
END;
DBMS_OUTPUT in Oracle SQL Developer
SET SERVEROUTPUT ON FORMAT WRAPED;
BEGIN
    DBMS_OUTPUT.ENABLE;
    DBMS_OUTPUT.PUT_LINE('Hello oracle!');
END;