Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package carrental;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- public class CarManagerImpl implements CarManager {
- public void addCar(Car car) {
- PreparedStatement insert = null;
- Connection conn = null;
- String url="jdbc:derby://localhost:1527/rental [marek on MAREK]";
- try {
- conn = DriverManager.getConnection(url,"marek","matus");
- insert = conn.prepareStatement("INSERT INTO APP.CAR " +
- "(VIN, COLOR, TYPE, PRICEPERDAY, SPZ)" +
- "values (?,?,?,?,?)");
- insert.setInt(1, car.getVin());
- insert.setInt(2, car.getColor());
- insert.setString(3, car.getType());
- insert.setInt(4, car.getPricePerDay());
- insert.setString(5, car.getSpz());
- insert.execute();
- } catch (SQLException ex) {
- ex.printStackTrace();
- } finally {
- if (conn != null) {
- try {
- conn.close();
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- if (insert != null) {
- try {
- insert.close();
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- }
- }
- public boolean removeCar(Car car) {
- boolean ret = false;
- PreparedStatement delete = null;
- Connection conn = null;
- String url="jdbc:derby://localhost:1527/rental [marek on MAREK]";
- try {
- conn = DriverManager.getConnection(url,"marek","matus");
- delete = conn.prepareStatement("DELETE FROM APP.CAR WHERE VIN = (?)");
- delete.setInt(1, car.getVin() );
- if (delete.executeUpdate() != 0) {
- ret = true;
- }
- } catch (SQLException ex) {
- ex.printStackTrace();
- } finally {
- if (conn != null) {
- try {
- conn.close();
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- if (delete != null) {
- try {
- delete.close();
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- }
- return ret;
- }
- public Car findCarByVin(int vin) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
- public Car editCar(Car car) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement