Skip to content
Snippets Groups Projects
Commit a5420521 authored by marruiz's avatar marruiz :space_invader:
Browse files

ghña

parent 1081a215
Branches
No related tags found
No related merge requests found
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package saii.dominio.DB;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import saii.dominio.RelationGeneralData1;
/**
*
* @author Agapormis
*/
public class RelationGeneralData1DB {
public static int insertarRGD1(RelationGeneralData1 relation) {
if (relation == null) {
throw new IllegalArgumentException("Relation igual a null");
}
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = (Connection) pool.getConnection();
PreparedStatement ps = null;
String query = "INSERT INTO RelationGeneralData1(warType, type_of_conflict) VALUES (?,?)";
try {
ps = connection.prepareStatement(query);
ps.setString(1, relation.getWarType() + "");
ps.setString(2, relation.getType_of_conflict()+ "");
int res = ps.executeUpdate();
ps.close();
pool.freeConnection(connection);
return res;
} catch (SQLException e) {
e.printStackTrace();
return 0;
}
}
public static RelationGeneralData1 selectWarType(int warType) {
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String query = "SELECT * FROM RelationGeneralData1 WHERE warType = ?";
try {
ps = connection.prepareStatement(query);
ps.setString(1, warType + "");
rs = ps.executeQuery();
RelationGeneralData1 relation = null;
if (rs.next()) {
relation = new RelationGeneralData1();
relation.setWarType((int) Double.parseDouble(rs.getString("warType")));
relation.setType_of_conflict(rs.getString("type_of_conflict"));
}
rs.close();
ps.close();
pool.freeConnection(connection);
return relation;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment