- Timestamp:
- 2020-10-20T11:35:49+13:00 (3 years ago)
- Location:
- main/trunk/model-sites-dev/cambridge-museum/collect/waikato-independent/pre-import/MSAccessToCSV
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-sites-dev/cambridge-museum/collect/waikato-independent/pre-import/MSAccessToCSV/pom.xml
r34492 r34501 25 25 <version>5.0.0</version> 26 26 </dependency> 27 28 <!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc --> 29 <dependency> 30 <groupId>org.xerial</groupId> 31 <artifactId>sqlite-jdbc</artifactId> 32 <version>3.32.3.2</version> 33 </dependency> 34 35 <!-- 36 <dependency> 37 <groupId>mysql</groupId> 38 <artifactId>mysql-connector-java</artifactId> 39 <version>8.0.22</version> 40 </dependency> 41 --> 27 42 28 43 <dependency> -
main/trunk/model-sites-dev/cambridge-museum/collect/waikato-independent/pre-import/MSAccessToCSV/src/main/java/org/greenstone/accessdb/JDBCBase.java
r34500 r34501 2 2 3 3 import java.sql.*; 4 import java.io.OutputStreamWriter;5 4 6 5 public class JDBCBase -
main/trunk/model-sites-dev/cambridge-museum/collect/waikato-independent/pre-import/MSAccessToCSV/src/main/java/org/greenstone/accessdb/MSAccessToCSV.java
r34499 r34501 6 6 public class MSAccessToCSV extends JDBCBase 7 7 { 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 72 9 public static void msAccessTableToCSVFile(Connection connection, String table_name, String csv_filename) 73 10 { … … 166 103 167 104 msAccessTableToCSVFile(connection, TABLE_NAME, csv_filename); 168 169 105 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) { 200 108 ex.printStackTrace(); 201 109 }
Note:
See TracChangeset
for help on using the changeset viewer.