daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest Feb 14th, 2018 61 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. package dao;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.SQLException;
  6.  
  7. import javax.sql.DataSource;
  8.  
  9. import model.Person;
  10.  
  11. public class PersonJDBCDAOImpl implements PersonJDBCDAO {
  12.  
  13.     private final static String INSERT_PERSON = "insert into person (id, name, surname, birthYear) values (?,?,?,?)";
  14.  
  15.     private DataSource dataSource;
  16.  
  17.     // DataSource bizim için connection sağlar, bağlantılarımızı yönetiriz.
  18.  
  19.     public PersonJDBCDAOImpl(DataSource dataSource) {
  20.         super();
  21.         this.dataSource = dataSource;
  22.     }
  23.  
  24.     @Override
  25.     public void insert(Person person) throws SQLException {
  26.  
  27.         try {
  28.             Connection connection = dataSource.getConnection();
  29.             PreparedStatement preparedStatement = connection.prepareStatement(INSERT_PERSON);
  30.             preparedStatement.setInt(1, person.getId());
  31.             preparedStatement.setString(2, person.getName());
  32.             preparedStatement.setString(3, person.getSurname());
  33.             preparedStatement.setInt(4, person.getBirthYear());
  34.             preparedStatement.executeUpdate();
  35.             preparedStatement.close();
  36.  
  37.             // logging
  38.             System.out.println("Person is inserted..." + person);
  39.         } catch (SQLException e) {
  40.             e.printStackTrace();
  41.         }
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top