Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package carRentalRefactoring;
- import com.opencsv.CSVReader;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import java.io.*;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- public class DBInserting {
- private String url = "jdbc:oracle:thin:@localhost:1521:xe";
- private String user = "admin_01";
- private String password = "admin";
- private Car car;
- public static class Builder{
- private String url;
- private String user;
- private String password;
- private Car car;
- public Builder setUrl(String url){
- this.url = url;
- return this;
- }
- public Builder setUser(String user){
- this.user = user;
- return this;
- }
- public Builder setPassword(String password){
- this.password = password;
- return this;
- }
- public Builder setCar(Car car) {
- this.car = car;
- return this;
- }
- public DBInserting build(){
- DBInserting insert = new DBInserting();
- insert.url = this.url;
- insert.user = this.user;
- insert.password = this.password;
- insert.car = this.car;
- return insert;
- }
- }
- public String getUrl(){
- return url;
- }
- public String getUser(){
- return user;
- }
- public String getPassword(){
- return password;
- }
- public Car getCar() {
- return car;
- }
- public void WriteToDB(Car machine,String query)
- throws SQLException {
- Connection connect = DriverManager.getConnection(url, user, password);
- PreparedStatement execute = connect.prepareStatement(query);
- execute.setString(1,machine.getRegistrationNumber());
- execute.setInt(2, (int) machine.getCurrentMileage());
- execute.setInt(3, machine.getDailyRate());
- execute.setFloat(4, machine.getEngineSize());
- execute.setInt(5, machine.getProductionYear());
- execute.setInt(6, machine.getYearRating());
- execute.executeUpdate();
- execute.close();
- }
- }
Add Comment
Please, Sign In to add comment