Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static final String URL = "jdbc:h2:tcp://localhost/~/demo_jdbc";
- public static final String USER = "demo_user";
- public static final String PASSWORD = "demo";
- public static void main(String... args) {
- Main main = new Main();
- main.insert(10, "山田 たろう");
- //...
- }
- public void insert(int id, String name) {
- try (Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);) {
- String sql = "INSERT INTO TBL_ES0206 (ID, DATA, REG_DAY, UPD_DAY) VALUES (?, ?, SYSDATE, SYSDATE)";
- try (PreparedStatement pstmt = conn.prepareStatement(sql);) {
- pstmt.setInt(1, id);
- pstmt.setString(2, name);
- conn.commit();
- } catch (SQLException ex) {
- ex.printStackTrace();
- if (conn!= null) {
- conn.rollback();
- }
- }
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement