Estou com problema na execução da classe abaixo:
[code] import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import oracle.jdbc.driver.OracleDriver;
public class Principal
{ public static void main (String[] args)
{ Connection conn = null;
try
{ DriverManager.registerDriver (new OracleDriver());
/*conn = DriverManager.getConnection
("jdbc:oracle:thin:@sbd:1521:orcl","java01","java01");*/
conn = DriverManager.getConnection
("jdbc:oracle:oci:@127.0.0.1:1521:xe","java01","java01");
}
catch (SQLException e)
{ System.out.println ('\n' + "Erro na conexão com o banco.");
e.printStackTrace();
System.exit(1);
}
int dia = 15;
int mes = 7;
int ano = 2000;
int hora = 10;
int minuto = 30;
int segundo = 12;
int nanoSegundos = 0;
SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
SimpleDateFormat sdf3 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date umaData = Date.valueOf(ano + "-" + mes + "-" + dia);
Time umaHora = Time.valueOf(hora + ":" + minuto + ":" + segundo);
Timestamp umaDataHora = Timestamp.valueOf(ano + "-" +
mes + "-" +
dia + " " +
hora + ":" +
minuto + ":" +
segundo + "." +
nanoSegundos);
System.out.println("Data: " + sdf1.format(umaData));
System.out.println("Hora: " + sdf2.format(umaHora));
System.out.println("Data e Hora: " + sdf3.format(umaDataHora));
System.out.println("");
try
{ PreparedStatement pstmt = conn.prepareStatement
("INSERT INTO DATAS(DATA, HORA, DATA_HORA) " +
"VALUES (?, ?, ?)");
pstmt.setDate (1, umaData);
pstmt.setTime (2, umaHora);
pstmt.setTimestamp (3, umaDataHora);
pstmt.executeUpdate();
pstmt.close();
}
catch(SQLException e)
{ System.out.println ('\n' + "Erro ao inserir os dados.");
e.printStackTrace();
System.exit(1);
}
try
{ PreparedStatement pstmt = conn.prepareStatement
("SELECT DATA, HORA, DATA_HORA FROM DATAS");
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{ umaData = rs.getDate("DATA");
umaHora = rs.getTime("HORA");
umaDataHora = rs.getTimestamp("DATA_HORA");
System.out.println("Data: " + sdf1.format(umaData));
System.out.println("Hora: " + sdf2.format(umaHora));
System.out.println("Data e Hora: " + sdf3.format(umaDataHora));
}
pstmt.close();
conn.close();
}
catch (SQLException e)
{ e.printStackTrace();
System.exit(1);
}
}
}[/code]
Na execuçaõ gera o seguinte erro:
Exception in thread “main” java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
at java.sql.Timestamp.valueOf(Unknown Source)
at Principal.main(Principal.java:47)
Alguem pode me ajudar.
Grato.