• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Guys and Girls use this cool program for output

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package jdbcpackage;
import java.sql.*;
public class DataFormating{
static ResultSetMetaData metadata;
static int columnCount;
// Format any ResultSet with this methods //
// ResultSet st is the ResultSet object in your class,RSMD is the RSMD object in your class
// int num is the numbers of columns in your ResultSet.
publicstatic void formatData(ResultSet st,ResultSetMetaData rsmd)throws SQLException{
metadata = rsmd;
columnCount = rsmd.getColumnCount();
for(int columns=1;columns<=columnCount;columns++){
String rowData = st.getString(columns);
String title = rsmd.getColumnName(columns);
System.out.print(rowData);
int j = 0;
while(j<((title.length())-(rowData.length())+20)){
System.out.print(" ");
j++;
}
}
System.out.println();
}
// Format any ResultSet with this methods //
// ResutlSetMetaData is the RSMD object in your class.
// int num is the numbers of columns in your ResultSet.
// For parting the Title from the Data columns.
publicstaticvoid formatTitle(ResultSetMetaData rsmd)throws SQLException{
columnCount = rsmd.getColumnCount();
for(int columns=1;columns<=columnCount;columns++){
System.out.print(rsmd.getColumnName(columns));
int j = 0;
while(j<20){
System.out.print(" ");
j++;
}
}System.out.println();
int k=0;
while(k<=getNameLength(rsmd)){
System.out.print( "-");
k++;
}
System.out.println();
}
public static int getNameLength(ResultSetMetaData rsmd) throws SQLException{
int len=0;
for(int i = 0;i<rsmd.getColumnCount();i++){>
len += rsmd.getColumnName(i+1).length();
}
return (len+((rsmd.getColumnCount()-1)*20))-1;
}
}
/*
eg: How to use this program
Resultset_object = Statement_object.createStatement();
Resultset_object = statement.executeQuery("select * from emp_table");
DataFormating.formatTitle(ResultSet set);
DataFormating.formatData(ResultSet set,ResultSetMetaData rsmd);
*/
Hope u get it and use it try it seriously it is a very good program and let me know how u find it.
 
His brain is the size of a cherry pit! About the size of this ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic