IBM Maximo: Java code to cleanup WOGEN table
import java.sql.*;
public class CleanupWogenProd { // java -cp ojdbc8.jar;. CleanupWogenProd
public static void main(String[] args) {
String jdbcUrl = "jdbc:oracle:thin:@//localhost:1521/maximodatabase"; // Update with your Oracle connection URL
String username = "USERDB"; // Update with your Oracle username
String password = "PASSWORD"; // Update with your Oracle password
try {
// Establish a connection to the Oracle database
Connection connection = DriverManager.getConnection(jdbcUrl, username, password);
// Disable auto-commit to start a transaction
connection.setAutoCommit(false);
// Create a SQL statement for deleting records
// String deleteQuery = "DELETE FROM WOGEN WHERE RUNDATE < sysdate-10 and rownum <= 1000";
String deleteQuery = "DELETE FROM WOGEN WHERE rownum <= 1000";
// Execute the delete statement until the table becomes empty
int i=1000;
int rowCount;
do {
// Create a prepared statement
PreparedStatement preparedStatement = connection.prepareStatement(deleteQuery);
// Execute the delete statement
rowCount = preparedStatement.executeUpdate();
// Commit the transaction
connection.commit();
// Close the prepared statement
preparedStatement.close();
System.out.println("i = " + i);
i = i + 1000;
} while (rowCount > 0);
// Close the connection
connection.close();
System.out.println("Table records deleted successfully!");
} catch (SQLException e) {
e.printStackTrace();
}
}
}