// Fig. 18.24: ParmGet.java // This program displays the contents of the Authors table // in the Books database. import java.sql.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; public class ParmValueGet extends JFrame { public String [][] parms; private Connection connection; private JTable table; //public noRows; String [][] pValue; public ParmValueGet(String [][] s, int i2) { // The URL specifying the Books database to which // this program connects using JDBC to connect to a // Microsoft ODBC database. pValue=new String[i2][]; String url = "jdbc:odbc:xshell"; String username = ""; String password = ""; // Load the driver to allow connection to the database try { Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ); connection = DriverManager.getConnection( url, username, password ); } catch ( ClassNotFoundException cnfex ) { System.err.println( "Failed to load JDBC/ODBC driver." ); cnfex.printStackTrace(); System.exit( 1 ); // terminate program } catch ( SQLException sqlex ) { System.err.println( "Unable to connect" ); sqlex.printStackTrace(); } getTable(s); shutDown(); } private void getTable(String[][] s) { Statement statement; ResultSet resultSet; try { String query= "SELECT parameterValues.parameter_name, parameterValues.parameter_value FROM parameterValues"; statement = connection.createStatement(); resultSet = statement.executeQuery( query ); displayResultSet( resultSet ); statement.close(); } catch ( SQLException sqlex ) { System.err.println( "Error with parameterValues"); sqlex.printStackTrace(); } } private void displayResultSet( ResultSet rs ) throws SQLException { // position to first record boolean moreRecords = rs.next(); // If there are no records, display a message if ( ! moreRecords ) { JOptionPane.showMessageDialog( this, "ResultSet contained no records" ); return; } Vector columnHeads = new Vector(); Vector rows = new Vector(); try { // get column heads ResultSetMetaData rsmd = rs.getMetaData(); for ( int i = 1; i <= rsmd.getColumnCount(); ++i ) columnHeads.addElement( rsmd.getColumnName( i ) ); // get row data int b=0; int j2=0; String str=""; int c=0; int j=0; String [] s1=new String [1000]; do { for ( int i = 1; i <= rsmd.getColumnCount(); ++i ){ if(j==0&&i==1){ str=rs.getString(i); } if(i==1&&j!=0){ String str2=rs.getString(i); if(str.equals(str2)){} else{ String [] st2=new String[j]; int j4=0; while(j4