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

ghña

parent 43fac3ee
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.ReligionData;
/**
*
* @author Agapormis
*
*
*/
public class ReligionDataDB {
public static int insertarReligionData(ReligionData religion) {
if (religion == null) {
throw new IllegalArgumentException("Religion igual a null");
}
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = (Connection) pool.getConnection();
PreparedStatement ps = null;
String query = "INSERT INTO ReligionData(year, country, religionName, religionNamePer, numberPeople) VALUES (?,?,?,?,?)";
try {
ps = connection.prepareStatement(query);
ps.setString(1, religion.getYear() + "");
ps.setString(2, religion.getCountry() + "");
ps.setString(3, religion.getReligionName() + "");
ps.setString(4, religion.getReligionNamePer()+ "");
ps.setString(5, religion.getNumberPeople()+ "");
int res = ps.executeUpdate();
ps.close();
pool.freeConnection(connection);
return res;
} catch (SQLException e) {
e.printStackTrace();
return 0;
}
}
public static ReligionData selectYear(int year) {
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String query = "SELECT * FROM ReligionData WHERE year = ?";
try {
ps = connection.prepareStatement(query);
ps.setString(1, year + "");
rs = ps.executeQuery();
ReligionData religion = null;
if (rs.next()) {
religion = new ReligionData();
religion.setYear((int) Double.parseDouble(rs.getString("year")));
religion.setCountry(rs.getString("country"));
religion.setReligionName(rs.getString("religionName"));
religion.setReligionNamePer(Double.parseDouble(rs.getString("religionNamePer")));
religion.setNumberPeople((int) Double.parseDouble(rs.getString("numberPeople")));
}
rs.close();
ps.close();
pool.freeConnection(connection);
return religion;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static ReligionData selectCountry(int country) {
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String query = "SELECT * FROM ReligionData WHERE country = ?";
try {
ps = connection.prepareStatement(query);
ps.setString(1, country + "");
rs = ps.executeQuery();
ReligionData religion = null;
if (rs.next()) {
religion = new ReligionData();
religion.setYear((int) Double.parseDouble(rs.getString("year")));
religion.setCountry(rs.getString("country"));
religion.setReligionName(rs.getString("religionName"));
religion.setReligionNamePer(Double.parseDouble(rs.getString("religionNamePer")));
religion.setNumberPeople((int) Double.parseDouble(rs.getString("numberPeople")));
}
rs.close();
ps.close();
pool.freeConnection(connection);
return religion;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static ReligionData selectReligionName(int religionName) {
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String query = "SELECT * FROM ReligionData WHERE religionName = ?";
try {
ps = connection.prepareStatement(query);
ps.setString(1, religionName + "");
rs = ps.executeQuery();
ReligionData religion = null;
if (rs.next()) {
religion = new ReligionData();
religion.setYear((int) Double.parseDouble(rs.getString("year")));
religion.setCountry(rs.getString("country"));
religion.setReligionName(rs.getString("religionName"));
religion.setReligionNamePer(Double.parseDouble(rs.getString("religionNamePer")));
religion.setNumberPeople((int) Double.parseDouble(rs.getString("numberPeople")));
}
rs.close();
ps.close();
pool.freeConnection(connection);
return religion;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment