Oracle挿入timestampタイプデータ


テーブル構造:
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に変換
作者:itmyhome
出典:http://blog.csdn.net/itmyhome1990/article/details/41776721