1 25 package com.mysql.jdbc.util; 26 27 import java.sql.ResultSet ; 28 import java.sql.ResultSetMetaData ; 29 import java.sql.SQLException ; 30 31 38 public class ResultSetUtil { 39 40 public static StringBuffer appendResultSetSlashGStyle( 41 StringBuffer appendTo, ResultSet rs) throws SQLException { 42 ResultSetMetaData rsmd = rs.getMetaData(); 43 44 int numFields = rsmd.getColumnCount(); 45 int maxWidth = 0; 46 47 String [] fieldNames = new String [numFields]; 48 49 for (int i = 0; i < numFields; i++) { 50 fieldNames[i] = rsmd.getColumnLabel(i + 1); 51 52 if (fieldNames[i].length() > maxWidth) { 53 maxWidth = fieldNames[i].length(); 54 } 55 } 56 57 int rowCount = 1; 58 59 while (rs.next()) { 60 appendTo.append("*************************** "); 61 appendTo.append(rowCount++); 62 appendTo.append(". row ***************************\n"); 63 64 for (int i = 0; i < numFields; i++) { 65 int leftPad = maxWidth - fieldNames[i].length(); 66 67 for (int j = 0; j < leftPad; j++) { 68 appendTo.append(" "); 69 } 70 71 appendTo.append(fieldNames[i]); 72 appendTo.append(": "); 73 74 String stringVal = rs.getString(i + 1); 75 76 if (stringVal != null) { 77 appendTo.append(stringVal); 78 } else { 79 appendTo.append("NULL"); 80 } 81 82 appendTo.append("\n"); 83 } 84 85 appendTo.append("\n"); 86 } 87 88 return appendTo; 89 } 90 } 91 | Popular Tags |