oracle表结构:
create table test(
id integer,
birthday timestamp
);
使用jdbc将日期插入到timestamp类型字段
import java.sql.connection;
import java.sql.drivermanager;
import java.sql.preparedstatement;
import java.sql.sqlexception;
import java.text.simpledateformat;
import java.util.date;
public class test {
static {
try {
class.forname(oracle.jdbc.driver.oracledriver);
} catch (classnotfoundexception e) {
e.printstacktrace();
}
}
/**
* 获得connection
*
* @return
*/
public static connection getconnection() {
connection conn = null;
try {
conn = drivermanager.getconnection(jdbc:oracle:thin:@localhost:1521/orcl, root, root);
} catch (sqlexception e) {
e.printstacktrace();
}
return conn;
}
public static void main(string[] args) throws sqlexception {
// todo auto-generated method stub
preparedstatement pst = null;
connection conn = getconnection();
simpledateformat df = new simpledateformat(yyyy-mm-dd hh:mm:ss);
string mydate = df.format(new date()); //当前时间
string sql = insert into test(id,birthday) values('1',to_timestamp(' + mydate + ','yyyy-mm-dd hh24:mi:ss'));
pst = conn.preparestatement(sql);
pst.executeupdate();
// 省略io流close
}
}
使用to_timestamp将字符型转成timestamp
在centos 6.4下安装oracle 11gr2(x64)
oracle 11gr2 在vmware虚拟机中安装步骤
debian 下 安装 oracle 11g xe r2
oracle linux 6.5安装oracle 11.2.0.4 x64
本文永久更新链接地址:
,
