Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.toc.toclite_web;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.UUID;
- import org.json.JSONObject;
- public class DBHandler {
- String url = "jdbc:mysql://master-tocdb.ciyw60nybde8.sa-east-1.rds.amazonaws.com:3306/";
- String dbName = "TOC_API";
- String driver = "com.mysql.jdbc.Driver";
- String userName = "tocdbadmin";
- String password = "Q9mkHUWF";
- String consulta = "";
- public String AgregarTRX(String f_id_source, String b_id_source, String selfie_source, JSONObject ID_data, String client_ID, double facial_score, boolean a_firma) throws SQLException {
- Connection conn = null;
- String resultado = "";
- try {
- Class.forName(driver).newInstance();
- conn = DriverManager.getConnection(url + dbName, userName, password);
- Statement st = conn.createStatement();
- //consulta = "select * from cliente where api_key = '" + api_key + "';";
- String Prefix = "";
- String hash = UUID.randomUUID().toString();
- consulta = "INSERT INTO tabla_trx (id, trx, front_photo, back_photo, selfie_photo, id_data, autorizado_firma, client_id, facial_score) VALUES " +
- "( '" + Prefix + "_" + hash + "', '"+ f_id_source + "', '" + b_id_source + "', '" + selfie_source + "', '" + ID_data.toString() + "', '" + a_firma + "', '" + client_ID + "', '" + facial_score + ";";
- //Need to see if id_data would be another table with a reference and how the TRX is created
- System.out.println(consulta);
- st.executeUpdate(consulta, Statement.RETURN_GENERATED_KEYS);
- ResultSet rs = st.getGeneratedKeys();
- if (rs.next()) {
- resultado = rs.getString(1);
- }
- rs.close();
- return resultado;
- } catch (Exception e) {
- System.out.println("Error en generarMail: " + e.toString());
- } finally {
- if (conn != null) {
- conn.close();
- }
- }
- return "";
- }
- public int veficarClient(String api_key) throws SQLException {
- Connection conn = null;
- boolean enabled = false;
- int response = 0;
- try {
- Class.forName(driver).newInstance();
- conn = DriverManager.getConnection(url + dbName, userName, password);
- String selectTableSQL = "select Activo from Cliente where api_key = '" + api_key + "';";
- System.out.println(selectTableSQL);
- Statement statement = conn.createStatement();
- ResultSet rs = statement.executeQuery(selectTableSQL);
- if (rs.next()) {
- response = rs.getInt("Activo");
- }
- conn.close();
- return response;
- } catch (Exception e) {
- System.out.println("Error en enabled: " + e.toString());
- } finally {
- if (conn != null) {
- conn.close();
- }
- }
- return response;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement