- createtableTEST(
- IDINTEGER,
- BIRTHDAYTIMESTAMP
- );
- importjava.sql.Connection;
- importjava.sql.DriverManager;
- importjava.sql.PreparedStatement;
- importjava.sql.sqlException;
- importjava.text.SimpleDateFormat;
- importjava.util.Date;
- publicclassTest{
- static{
- try{
- Class.forName("oracle.jdbc.driver.OracleDriver");
- }catch(ClassNotFoundExceptione){
- e.printStackTrace();
- }
- }
- /**
- *获得Connection
- *
- *@return
- */
- publicstaticConnectiongetConnection(){
- Connectionconn=null;
- try{
- conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/orcl","root","root");
- }catch(sqlExceptione){
- e.printStackTrace();
- }
- returnconn;
- }
- publicstaticvoidmain(String[]args)throwssqlException{
- //TODOAuto-generatedmethodstub
- PreparedStatementpst=null;
- Connectionconn=getConnection();
- SimpleDateFormatdf=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");
- StringmyDate=df.format(newDate());//当前时间
- Stringsql="insertintotest(id,birthday)values('1',to_timestamp('"+myDate+"','yyyy-mm-ddhh24:mi:ss'))";
- pst=conn.prepareStatement(sql);
- pst.executeUpdate();
- //省略IO流close
- }
- }