Ignore:
Timestamp:
2020-10-20T11:35:49+13:00 (4 years ago)
Author:
davidb
Message:

Code tidy up

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-sites-dev/cambridge-museum/collect/waikato-independent/pre-import/MSAccessToCSV/src/main/java/org/greenstone/accessdb/MSAccessToCSV.java

    r34499 r34501  
    66public class MSAccessToCSV extends JDBCBase
    77{
    8     /*
    9    
    10     final static String TABLE_NAME = "WAIKATO_INDEPENDENT";
    11    
    12     public static void printDatabaseMetadata(Connection connection)
    13     {
    14         try {
    15 
    16         System.out.println("----");
    17         System.out.println("Database Table Names");
    18         System.out.println("----");
    19             DatabaseMetaData dbmd = connection.getMetaData();
    20             String[] types = {"TABLE"};
    21             ResultSet rs = dbmd.getTables(null, null, "%", types);
    22             while (rs.next()) {
    23                 System.out.println(rs.getString("TABLE_NAME"));
    24             }
    25         System.out.println("----");
    26         }
    27             catch (SQLException e) {
    28             e.printStackTrace();
    29         }
    30     }
    31 
    32     public static void printTable(Connection connection, String table_name)
    33     {
    34     try {
    35         Statement st = connection.createStatement();
    36         ResultSet rs = st.executeQuery("SELECT * from " + table_name);
    37         ResultSetMetaData rsmd = rs.getMetaData();
    38        
    39         int columnsNumber = rsmd.getColumnCount();                     
    40        
    41         // Iterate through the data in the result set and display it.
    42         System.out.println("----");
    43         System.out.println("Table: " + table_name);
    44         System.out.println("----");
    45 
    46         for(int i = 1; i <= columnsNumber; i++) {
    47         System.out.print(rsmd.getColumnLabel(i)+ "|");
    48         }
    49         System.out.println();
    50        
    51         while (rs.next()) {
    52         for(int i = 1 ; i <= columnsNumber; i++){
    53             System.out.print(rs.getString(i));
    54             if (i != columnsNumber) { System.out.print(","); }
    55         }
    56        
    57         System.out.println();
    58        
    59         }
    60            
    61         System.out.println("----");
    62        
    63     }
    64     catch (Exception e) {
    65         e.printStackTrace();
    66     }
    67    
    68     }
    69 
    70     */
    71    
     8 
    729    public static void msAccessTableToCSVFile(Connection connection, String table_name, String csv_filename)
    7310    {
     
    166103       
    167104        msAccessTableToCSVFile(connection, TABLE_NAME, csv_filename);
    168 
    169105       
    170         /*
    171             String sql = "INSERT INTO Contacts (Full_Name, Email, Phone) VALUES (?, ?, ?)";
    172              
    173             PreparedStatement preparedStatement = connection.prepareStatement(sql);
    174             preparedStatement.setString(1, "Jim Rohn");
    175             preparedStatement.setString(2, "[email protected]");
    176             preparedStatement.setString(3, "0919989998");
    177              
    178             int row = preparedStatement.executeUpdate();
    179              
    180             if (row > 0) {
    181                 System.out.println("A row has been inserted successfully.");
    182             }
    183              
    184             sql = "SELECT * FROM Contacts";
    185              
    186             Statement statement = connection.createStatement();
    187             ResultSet result = statement.executeQuery(sql);
    188              
    189             while (result.next()) {
    190                 int id = result.getInt("Contact_ID");
    191                 String fullname = result.getString("Full_Name");
    192                 String email = result.getString("Email");
    193                 String phone = result.getString("Phone");
    194                  
    195                 System.out.println(id + ", " + fullname + ", " + email + ", " + phone);
    196             }
    197         */
    198        
    199         } catch (SQLException ex) {
     106        }
     107    catch (SQLException ex) {
    200108            ex.printStackTrace();
    201109        }
Note: See TracChangeset for help on using the changeset viewer.