Insert Dates into Database - Java JDBC

Java examples for JDBC:SQL Statement

Description

Insert Dates into Database

Demo Code

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.time.LocalDate;

public class Main {
  static Connection conn = null;

  private static void insertRecord()throws Exception {
    String sql = "INSERT INTO PUBLICATION VALUES("
        + "NEXT VALUE FOR PUBLICATION_SEQ, ?,?,?)";
    LocalDate pubDate = LocalDate.now();
    PreparedStatement pstmt = conn.prepareStatement(sql);
    pstmt.setInt(1, 100);//from   w w  w . j  a v  a2  s . c  om
    pstmt.setString(2, "title");
    pstmt.setDate(3, java.sql.Date.valueOf(pubDate));
    pstmt.executeUpdate();

  }
}

Related Tutorials