Advertisement
Guest User

DBa

a guest
Jul 24th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. package com.toc.toclite_web;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.util.UUID;
  9. import org.json.JSONObject;
  10.  
  11. public class DBHandler {
  12.  
  13. String url = "jdbc:mysql://master-tocdb.ciyw60nybde8.sa-east-1.rds.amazonaws.com:3306/";
  14. String dbName = "TOC_API";
  15. String driver = "com.mysql.jdbc.Driver";
  16. String userName = "tocdbadmin";
  17. String password = "Q9mkHUWF";
  18. String consulta = "";
  19.  
  20.  
  21. 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 {
  22. Connection conn = null;
  23. String resultado = "";
  24. try {
  25. Class.forName(driver).newInstance();
  26. conn = DriverManager.getConnection(url + dbName, userName, password);
  27. Statement st = conn.createStatement();
  28. //consulta = "select * from cliente where api_key = '" + api_key + "';";
  29. String Prefix = "";
  30. String hash = UUID.randomUUID().toString();
  31.  
  32. consulta = "INSERT INTO tabla_trx (id, trx, front_photo, back_photo, selfie_photo, id_data, autorizado_firma, client_id, facial_score) VALUES " +
  33. "( '" + Prefix + "_" + hash + "', '"+ f_id_source + "', '" + b_id_source + "', '" + selfie_source + "', '" + ID_data.toString() + "', '" + a_firma + "', '" + client_ID + "', '" + facial_score + ";";
  34.  
  35. //Need to see if id_data would be another table with a reference and how the TRX is created
  36.  
  37. System.out.println(consulta);
  38. st.executeUpdate(consulta, Statement.RETURN_GENERATED_KEYS);
  39.  
  40. ResultSet rs = st.getGeneratedKeys();
  41. if (rs.next()) {
  42. resultado = rs.getString(1);
  43. }
  44. rs.close();
  45.  
  46. return resultado;
  47. } catch (Exception e) {
  48.  
  49. System.out.println("Error en generarMail: " + e.toString());
  50.  
  51. } finally {
  52. if (conn != null) {
  53. conn.close();
  54. }
  55. }
  56. return "";
  57. }
  58.  
  59. public int veficarClient(String api_key) throws SQLException {
  60. Connection conn = null;
  61. boolean enabled = false;
  62. int response = 0;
  63. try {
  64. Class.forName(driver).newInstance();
  65. conn = DriverManager.getConnection(url + dbName, userName, password);
  66.  
  67. String selectTableSQL = "select Activo from Cliente where api_key = '" + api_key + "';";
  68. System.out.println(selectTableSQL);
  69.  
  70. Statement statement = conn.createStatement();
  71. ResultSet rs = statement.executeQuery(selectTableSQL);
  72. if (rs.next()) {
  73. response = rs.getInt("Activo");
  74. }
  75. conn.close();
  76. return response;
  77. } catch (Exception e) {
  78. System.out.println("Error en enabled: " + e.toString());
  79. } finally {
  80. if (conn != null) {
  81. conn.close();
  82. }
  83. }
  84. return response;
  85. }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement