标签:
/**
* 插入oracle TimeStamp类型
*/
public void insertTimeStamp(){
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String myDate = sdf.format(new Date()); //当前时间
String sql = "insert into table1 values(‘‘, to_date(‘"+myDate+"‘, ‘yyyy-MM-dd hh24:mi:ss‘))";
Connection conn = BaseConnection.getConnection();
PreparedStatement ps = null;
ps = conn.prepareStatement(sql);
int a = ps.executeUpdate();
if (a > 0) {
System.out.println("insert is successful...");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void insertData(){
try {
// java.util.Date utilDate = new java.util.Date(sqlDate.getTime());
// java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
// java.util.Date utilDate = dateFormat.parse(sqlDate.toString());
java.util.Date a = new java.util.Date();
java.sql.Timestamp d=new java.sql.Timestamp(a.getTime());
// String myDate = df.format(new Date()); //当前时间
String sql = "insert into table1 values(‘"+d+"‘, ‘‘)";
Connection conn = BaseConnection.getConnection();
PreparedStatement ps = null;
ps = conn.prepareStatement(sql);
int abc = ps.executeUpdate();
if (abc > 0) {
System.out.println("insert is successful...");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
标签:
原文地址:http://www.cnblogs.com/dl30373/p/4725876.html