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가 오므로 두번째 파라미터부터 해당 프로시저의 첫번째 파라미터의 정보를 가져올수가 있습니다.
'JAVA Platform > JAVA' 카테고리의 다른 글
[JAVA} - JDBC 프로시저명 가져오기 (0) | 2015.09.30 |
---|---|
[JAVA] - Swing Progress JWindow Example (0) | 2015.08.21 |
[JAVA] - SQL_Server JDBC 드라이버 sqljdbc.jar 와 sqljdbc4.jar 차이점 (0) | 2015.07.23 |
[JAVA] - AWT/Swing 기본 Component Text 영어로 변경하기 (0) | 2015.05.15 |
[JAVA] - 환경변수 목록 가져오기 (0) | 2015.04.28 |