Huge Sell on Popular Electronics
# 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" + columnNames[col]);
}
for(int row=0; row\n ");
String[] rowData = getRow(row);
for(int col=0; col" + rowData[col]);
}
}
buffer.append("\n");
return(buffer.toString());
}
}
Huge Sell on Popular Electronics
এই সাধারণ উদ্দেশ্যে তৈরিকৃত কোড নয় - এটা আমাদের লোকাল সেটআপ এর ক্ষেত্রে প্রযোজ্য।
package cwp;
/** Some simple utilities for building Oracle and Sybase
* JDBC connections. This is not general-purpose
* code -- it is specific to my local setup.
*/
public class DriverUtilities {
public static final int ORACLE = 1;
public static final int SYBASE = 2;
public static final int UNKNOWN = -1;
/** Build a URL in the format needed by the
* Oracle and Sybase drivers I am using.
*/
public static String makeURL(String host, String dbName,
int vendor) {
if (vendor == ORACLE) {
return("jdbc:oracle:thin:@" + host + ":1521:" + dbName);
} else if (vendor == SYBASE) {
return("jdbc:sybase:Tds:" + host + ":1521" +
"?SERVICENAME=" + dbName);
} else {
return(null);
}
}
/** Get the fully qualified name of a driver. */
public static String getDriver(int vendor) {
if (vendor == ORACLE) {
return("oracle.jdbc.driver.OracleDriver");
} else if (vendor == SYBASE) {
return("com.sybase.jdbc.SybDriver");
} else {
return(null);
}
}
/** Map name to int value. */
public static int getVendor(String vendorName) {
if (vendorName.equalsIgnoreCase("oracle")) {
return(ORACLE);
} else if (vendorName.equalsIgnoreCase("sybase")) {
return(SYBASE);
} else {
return(UNKNOWN);
}
}
}
Machine Learning, Big Data, Data Science, Analytics, Cloud, Security, AI, Robotics, Database, BI, Development: Software, Web, Mobile