您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Oracle插入timestamp类型数据

2025/12/12 1:27:55发布26次查看
oracle表结构: create table test( id integer, birthday timestamp); 使用jdbc将日期插入到timestamp类型字段 import
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
本文永久更新链接地址:

该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product