public static void showProcedureNameList() {
		Connection connection = null;
		ResultSet resultSet = null;
		try {
			Class.forName(className);
			connection = DriverManager.getConnection(url, user, password);
			resultSet = connection.getMetaData().getProcedures(null, connection.getMetaData().getUserName(), null);
			ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
			while (resultSet.next()) {
				if (resultSet.getInt(8) == 1) { ⁄⁄ StoredProcedure
					System.out.println("Procedure Name : " + resultSet.getString(3));
				} 
				for (int i = 1; i < resultSetMetaData.getColumnCount(); i++) {
					System.out.println("\t" + i + ". ColumnName : " + resultSetMetaData.getColumnName(i));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (resultSet != null) {
					resultSet.close();
				}
				
				if (connection != null) {
					connection.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}


ResultSetMetaData 정보를 통하여 8번째 인덱스값이 프로시저 타입을 가져오는 인덱스인걸 알수가 잇습니다. 

프로시저같은경우에는 타입이 1번이 되겠고 함수는 2번이 되겠습니다.

블로그 이미지

행복그리고..

,
     public static void run() {
		Connection conn = null;
		ResultSet rs = null;
		try {
			String theClassName = "", 
					  theURL = "", 
					  theUser = "", 
					  thePassword = "", 
					  theFunctionName = "";
			
			Class.forName(theClassName);
			conn = DriverManager.getConnection(theURL, theUser, thePassword);
			DatabaseMetaData dbmd = conn.getMetaData();
			rs = dbmd.getProcedureColumns(null, null, theFunctionName, null);
			ResultSetMetaData rsmd = rs.getMetaData();
			
			int columnIndex = 1;
			boolean setNoCount = true;
			String productName = dbmd.getDatabaseProductName();
			while (rs.next()) {
				if (productName.indexOf("Microsoft") != -1) {
					if (getParameterType(rs.getInt(5)).equalsIgnoreCase("Return") && setNoCount == true) {
						setNoCount = false;
						continue;
					}
				}
				System.out.println("----------------------------------------");
				System.out.println("Parameter " + columnIndex++);
				System.out.println("Parameter Type : " + getParameterType(rs.getInt(5)));
				System.out.println("Name : " + rs.getString(4));
				System.out.println("Data Type : " + rs.getString(7));
				for (int i = 1; i < rsmd.getColumnCount(); i ++) {
					System.out.println("\t" + i + " - ColumnLabel : " + rsmd.getColumnLabel(i) + " : " + rs.getString(i));
					System.out.println("\t\tColumnClassName : " + rsmd.getColumnClassName(i));
					System.out.println("\t\tColumnName : " + rsmd.getColumnName(i));
					System.out.println("\t\tColumnType : " + rsmd.getColumnType(i));
					System.out.println("\t\tColumnTypeName : " + rsmd.getColumnTypeName(i));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}

				if (conn != null) {
					conn.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	private static String getParameterType(final int metadataType) {
		switch (metadataType) {
		case DatabaseMetaData.procedureColumnUnknown :
            return "Unknown";
        case DatabaseMetaData.procedureColumnIn :
        	return "In";
        case DatabaseMetaData.procedureColumnInOut :
        	return "InOut";
        case DatabaseMetaData.procedureColumnOut :
        	return "Out";
        case DatabaseMetaData.procedureColumnReturn :
            return "Return";
        case DatabaseMetaData.procedureColumnResult :
            return "Result";
        default:
        	return "Unknown";
		}
	}

Oracle, SQLServer를 기준으로 작성하였습니다. SQLServer같은 경우에는 첫번째 파라미터로 setNoCount가 오므로 두번째 파라미터부터 해당 프로시저의 첫번째 파라미터의 정보를 가져올수가 있습니다.

블로그 이미지

행복그리고..

,

예를들어 스윙 어플리케이션에서 Progress를 뛰어주고 싶을경우에 사용하면 되겠습니다. 


Progress를 JDialog에서 생성하여 뛰워줘도 됩니다. 하지만 Progress 라는 것은 어떠한 작업을 할 경우


1. DataBase

2. File Load


... 등등이 되겠지요 가져오는 값들이 대용량일 경우에는 시간이 걸리기 때문에 이러한 상황에 대부분 Progress를 사용합니다. 

이러한 경우 타이틀바가 필요가 없게되고 작업이 다 끝났을 경우 Progress 는 사라지기 때문에 JDialog보다는 JWindow를 사용하여 구현하는게 좋겟지요 UI상에서도 보기 좋습니다.


Source Code

 

import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;


class SwingApp extends JFrame implements ComponentListener {

	private static final long serialVersionUID = -1706061272770838668L;
	private static final int APP_WIDTH = 600;
	private static final int APP_HEIGHT = 400;
	
	private ProgressWindow theProgressWindow;
	
	public SwingApp(String title) {
		super(title);
		setSize(APP_WIDTH, APP_HEIGHT);
		
		Dimension theScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension theFrameSize = getSize();
		int x = (int) (theScreenSize.getWidth() - theFrameSize.getWidth()) / 2;
		int y = (int) (theScreenSize.getHeight() - theFrameSize.getHeight()) / 2;
		
		this.setLocation(x, y);
		this.setResizable(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.addComponentListener(this);
	}
	
	public void appearView() {
		this.setVisible(true);
		theProgressWindow = new ProgressWindow(this);
		Thread destoryThread = new Thread(new Runnable() {
			public void run() {
				try {
					Thread.sleep(5000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				theProgressWindow.dispose();
			}
		});
		destoryThread.start();
	}
	
	public void componentResized(ComponentEvent e) { }
	public void componentMoved(ComponentEvent e) {
		this.theProgressWindow.setLocationRelativeTo(e.getComponent());
	}
	public void componentShown(ComponentEvent e) { }
	public void componentHidden(ComponentEvent e) { }
}
 
class ProgressWindow extends JWindow {
	
	private static final long serialVersionUID = -6524167698066722942L;
	private static final String userDir = System.getProperty("user.dir");
	
	private static final int PROGRESS_WIDTH = 50;
	private static final int PROGRESS_HEIGHT = 50;
	
	private JLabel imageLabel = new JLabel();
	
	public ProgressWindow(JFrame theFrame) {
		super(theFrame);
		
		setSize(200, 150);
		this.setLayout(null);
		this.getRootPane().getContentPane().setBackground(Color.YELLOW);
		String filePath = userDir + File.separator + "ajax-loader.gif";
		ImageIcon imageIcon = new ImageIcon(filePath);
		
		Dimension theWindowSize = getSize();
		Dimension theLabelSize = new Dimension(PROGRESS_WIDTH, PROGRESS_HEIGHT);
		int x = (int) (theWindowSize.getWidth() - theLabelSize.getWidth()) / 2;
		int y = (int) (theWindowSize.getHeight() - theLabelSize.getHeight()) / 2;
		
		imageLabel.setIcon(imageIcon);
		imageLabel.setBounds(x, y, PROGRESS_WIDTH, PROGRESS_HEIGHT);
		this.add(imageLabel);
		setLocationRelativeTo(theFrame);
		this.setVisible(true);
	}
}

public class SwingTest {
	public static void run() {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				SwingApp theApp = new SwingApp("Swing App");
				theApp.appearView();
			}
		});
	}
	
	public static void main(String[] args) {
		run();
	}
}

ajax-loader.gif File Download

URL :  http://www.ajaxload.info/ 

블로그 이미지

행복그리고..

,