Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. public static boolean Leer_conversaciones (List <Map<String,String>> lista_conversaciones, Connection connection, String id_chat, int ultimo_id_conversacion, String [] error){
  2. boolean ret = true;
  3. String comando = "select id_conversacion, texto, ref_usuario "
  4. + "from conversaciones "
  5. + "where id_conversacion > ? " //Desde el último recibido.
  6. + "and ref_chat = ? "
  7. + "order by "
  8. + "id_conversacion " // Ordenadas por el id_conversacion
  9. + "asc ";
  10. if (ultimo_id_conversacion == 0){ //Mi primera conexión.
  11. comando = comando + "limit 50"; //Las 50 últimas.
  12. } //De mayor a menor
  13. try {
  14. PreparedStatement preparestatement=connection.prepareStatement(comando);
  15. preparestatement.setInt(1, ultimo_id_conversacion);
  16. preparestatement.setString(2, id_chat);
  17. ResultSet resultset = preparestatement.executeQuery();
  18.  
  19. while (resultset.next()){
  20. String mensaje = resultset.getString("texto");
  21. int tam = mensaje.length();
  22. if (tam > 60){
  23. int i = 60;
  24. StringBuilder stringbuilder = new StringBuilder();
  25. stringbuilder.append(mensaje);
  26. while (true){
  27. if (stringbuilder.charAt(i) == ' ' || i >= stringbuilder.length()-1){
  28. stringbuilder.insert(i,"\n");
  29. break;
  30. }
  31. i++;
  32. }
  33. if (tam > 120){
  34. i = 120;
  35. while (true){
  36. if (stringbuilder.charAt(i) == ' ' || i >= stringbuilder.length()-1){
  37. stringbuilder.insert(i,"\n");
  38. break;
  39. }
  40. i++;
  41. }
  42. }
  43. if (tam > 180){
  44. i = 180;
  45. while (true){
  46. if (stringbuilder.charAt(i) == ' ' || i >= stringbuilder.length()-1){
  47. stringbuilder.insert(i,"\n");
  48. break;
  49. }
  50. i++;
  51. }
  52. }
  53. if (tam > 240){
  54. i = 240;
  55. while (true){
  56. if (stringbuilder.charAt(i) == ' ' || i >= stringbuilder.length()-1){
  57. stringbuilder.insert(i,"\n");
  58. break;
  59. }
  60. i++;
  61. }
  62. }
  63. mensaje = stringbuilder.toString();
  64. }
  65. String usuario = resultset.getString("ref_usuario");
  66. String id_conversacion = resultset.getString("id_conversacion");
  67. Map <String, String> entrada = new HashMap();
  68. entrada.put("texto", mensaje);
  69. entrada.put("usuario", usuario);
  70. entrada.put("id_conversacion", id_conversacion);
  71. lista_conversaciones.add(entrada);
  72. }
  73. preparestatement.close();
  74. resultset.close();
  75. }
  76. catch (Exception e){
  77. String mensaje = e.getMessage();
  78. if (mensaje == null) {
  79. mensaje = "";
  80. }
  81. error [0] = java.text.MessageFormat.format(java.util.ResourceBundle.getBundle("recursos/Bundle_controladores_clases_chats").getString("ERROR AL ACCEDER A LA CUENTA {0}"), new Object[] {mensaje});
  82. ret = false;
  83. }
  84. return ret;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement