List of utility methods to do SQL Table
String | normalizeTableName(String table, Connection con) normalize Table Name for (String t : getTables(con)) { if (t.equalsIgnoreCase(table)) { return t; return table; |
List | parse(Connection connection, String tableName, String type) parse List<String> result = new ArrayList<>(); try { ResultSet resultSet = null; if (type.equals("primary")) { resultSet = connection.getMetaData().getPrimaryKeys(null, null, tableName); } else { resultSet = connection.getMetaData().getColumns(null, null, tableName, null); while (resultSet.next()) { result.add(resultSet.getString("COLUMN_NAME").toLowerCase()); } catch (SQLException e) { e.printStackTrace(); return result; |
String | queryAllFromTable(String tableName) return a Statement with the result of a "SELECT *" query for a given table return "SELECT * FROM " + tableName + ';'; |
String | quoteSchemaTable(Connection conn, String schema, String table) Returns quoted schema & table to use in SQL queries for the given Connection. String dbms = getDbmsFromConnection(conn);
return quoteSchemaTable(dbms, schema, table);
|
void | truncateTable(Connection conn) truncate Table try (Statement statement = conn.createStatement()) { statement.execute("delete from TEST"); |
void | truncateTable(Connection conn, String table_name) truncate Table Statement truncateStmt = null; Statement countStmt = null; String truncateSQL = "TRUNCATE TABLE " + table_name; String countSQL = "SELECT COUNT(*) as count FROM " + table_name; try { truncateStmt = conn.createStatement(); truncateStmt.executeUpdate(truncateSQL); countStmt = conn.createStatement(); ... |
void | truncateTable(Connection conn, String tablename) truncate Table StringBuilder sb = new StringBuilder(); sb.append("TRUNCATE TABLE "); sb.append(tablename); String sql = sb.toString(); Statement stmt = null; try { stmt = conn.createStatement(); stmt.executeUpdate(sql); ... |