Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab3;
- import java.sql.*;
- import java.util.Properties;
- public class ResultEntity {
- private long id;
- private Double x;
- private Double y;
- private Double radius;
- private Boolean hit;
- public long getId() {
- return id;
- }
- public void setId(long id) {
- this.id = id;
- }
- public Double getX() {
- return x;
- }
- public void setX(Double x) {
- this.x = x;
- }
- public Double getY() {
- return y;
- }
- public void setY(Double y) {
- this.y = y;
- }
- public Double getRadius() {
- return radius;
- }
- public void setRadius(Double radius) {
- this.radius = radius;
- }
- public Boolean getHit() {
- return hit;
- }
- public void setHit(Boolean hit) {
- this.hit = hit;
- }
- public ResultEntity(Double x, Double y, Double radius, Boolean hit) {
- this.x = x;
- this.y = y;
- this.radius = radius;
- this.hit = hit;
- }
- public static void addElem(Double x, Double y, Double radius, boolean hit) throws Exception {
- Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:orbis", "s225282", "6awqhh");
- Statement statement = connection.createStatement();
- String select = "SELECT MAX(ID) FROM RESULT";
- ResultSet rs = statement.executeQuery(select);
- int id = 0;
- while (rs.next()) {
- id = rs.getInt(1);
- }
- id++;
- int int_hit = 0;
- if (hit)
- int_hit = 1;
- String insert = "INSERT INTO RESULT (ID, X, Y, RADIUS, HIT) VALUES " +
- "(" + id + ", " + x + ", " + y + ", " + radius + ", " + int_hit + ")";
- statement.execute(insert);
- }
- /**
- * @param db строка для соединения с базой в формате JDBC
- * @param props параметры для драйвера, такие как пользователь, пароль, порт и тд
- * @return соединение с БД
- * @throws SQLException
- */
- public static Connection getConnection(String db, Properties props) throws SQLException {
- Connection conn = DriverManager.getConnection(db, props);
- System.out.println(conn);
- return conn;
- }
- /**
- * @param host адрес хоста с БД
- * @param port поорт на котором листенер прослушивает соединение для указанного SID
- * @param sid идентификатор схемы БД
- * @param user пользоватьель
- * @param password и его пароль
- * @return параметры для соединения с Oracle DB
- */
- public static Properties createPropsOracle(String host, String port, String sid, String user, String password) {
- Properties props = new Properties();
- props.put("host", host);
- props.put("port", port);
- props.put("sid", sid);
- props.put("user", user);
- props.put("password", password);
- return props;
- }
- /**
- * Загружает JDBC драйвер по имени.
- * На самом деле это лишнее для всех современных БД. Вызывать loadDriver - НЕ обязательно
- *
- * @param driverFullName полное имя класса в котором реализован интерфейс вызова Driver для JDBC
- * @return загруженный класс
- * @throws ClassNotFoundException
- */
- public static Class loadDriver(String driverFullName) throws ClassNotFoundException {
- Class c = Class.forName(driverFullName);
- System.out.println(c);
- return c;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement