DBResults.java: Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways #Programming Code Examples #Java/J2EE/J2ME #JDBC


# DBResults.java  Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways:

    * ResultSet doesn?t necessarily have all the data; reconnection to database occurs as you ask for later rows.
    * This class stores results as strings, in arrays.
    * This class includes DatabaseMetaData (database product name and version) and ResultSetMetaData (the column names).
    * This class has a toHTMLTable method that turns the results into a long string corresponding to an HTML table. 




package cwp;

import java.sql.*;
import java.util.*;

/** Class to store completed results of a JDBC Query.
 *  Differs from a ResultSet in several ways:
 *  
    *
  • ResultSet doesn't necessarily have all the data; * reconnection to database occurs as you ask for * later rows. *
  • This class stores results as strings, in arrays. *
  • This class includes DatabaseMetaData (database product * name and version) and ResultSetMetaData * (the column names). *
  • This class has a toHTMLTable method that turns * the results into a long string corresponding to * an HTML table. *
*

*/ public class DBResults { private Connection connection; private String productName; private String productVersion; private int columnCount; private String[] columnNames; private Vector queryResults; String[] rowData; public DBResults(Connection connection, String productName, String productVersion, int columnCount, String[] columnNames) { this.connection = connection; this.productName = productName; this.productVersion = productVersion; this.columnCount = columnCount; this.columnNames = columnNames; rowData = new String[columnCount]; queryResults = new Vector(); } public Connection getConnection() { return(connection); } public String getProductName() { return(productName); } public String getProductVersion() { return(productVersion); } public int getColumnCount() { return(columnCount); } public String[] getColumnNames() { return(columnNames); } public int getRowCount() { return(queryResults.size()); } public String[] getRow(int index) { return((String[])queryResults.elementAt(index)); } public void addRow(String[] row) { queryResults.addElement(row); } /** Output the results as an HTML table, with * the column names as headings and the rest of * the results filling regular data cells. */ public String toHTMLTable(String headingColor) { StringBuffer buffer = new StringBuffer("

n"); if (headingColor != null) { buffer.append(" n "); } else { buffer.append(" n "); } for(int col=0; col<getcolumncount (); col++) { buffer.append("n "); String[] rowData = getRow(row); for(int col=0; col<getcolumncount (); col++) { buffer.append("
" + columnNames[col]); } for(int row=0; row<getrowcount (); row++) { buffer.append("n
" + rowData[col]); } } buffer.append("n
"); return(buffer.toString()); } }

Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10204
Categories:Programming Code Examples, Java/J2EE/J2ME, JDBC
Tags:Java/J2EE/J2MEJDBC
Post Data:2017-01-02 16:04:23

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada