My problem is this, I have to grab SQL insert lines and check if the formats in the TO_DATE function in these inserts are valid with a java method. For a 'DD / MM / YYYY' format, SimpleDateFormat solves my problem, but sometimes an insert is required in 'DD / MM / YYYY format HH24: MI: SS' and there SimpleDateFormat does not accept this format, how can I see this ? Here is the code for my Java method.
boolean retorno = true;
try {
if (line.matches(".*TO_DATE.*")) {
String[] linha_quebrada = line.split("TO_DATE");
ArrayList<String> datas = new ArrayList<String>();
for (int i = 0; i < linha_quebrada.length; i++) {
if (linha_quebrada[i].substring(0, 1).equalsIgnoreCase("(")) {
datas.add(linha_quebrada[i]);
}
}
for (int k = 0; k < datas.size(); k++) {
String toDate = null;
int inicio;
int fim;
if (datas.get(k).substring(0, 1).equalsIgnoreCase("(")) {
toDate = datas.get(k).substring(0, datas.get(k).length() - 1);
inicio = toDate.indexOf("(") + 1;
fim = toDate.indexOf(")");
toDate = toDate.substring(inicio, fim);
String[] data_formato = toDate.split(",");
String data = data_formato[0].replace("'", "");
String formato = data_formato[1].replace("'", "").trim();
/*java.sql.Date dateSQL = new Date*/
SimpleDateFormat formatoData = new SimpleDateFormat(formato);
Date dataJava = formatoData.parse(data);
System.out.println(dataJava.toString());
}
}
}
} catch (ParseException e) {
retorno = false;
}