0
My problem is the following, I have to take rows of SQL Insert and check whether 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 it is necessary an 'DD/MM/YYYY HH24:MI:SS' format and then Simpledateformat does not accept this format, how can I see it? Follow the code of 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;
}
I missed this link in the answer: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
– Jefferson Quesado
Resolve, but wanted to know a way to check all types of masks that exist in SQL, will have a way to put all of them so I can validate in this method that I created?
– Danilo Torres