elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


  Mostrar Temas
Páginas: [1] 2 3 4 5 6 7 8 9
1  Programación / Programación General / Matrix de Pantalla en: 9 Abril 2018, 23:16 pm
Hola a tod@s!!
espero que todos anden bien por aqui, me gustaria que me den algun consejo acerca de algo que quiero crear les cuento mi necesidad a ver si me dan ese consejo.

tengo una pantalla de 320 X 480 (en pixeles todo) tengo un matrix (apuntador de c++) sin tamaño asignado supongamos que estoy usando c++ aunque la implementacion puede ser en otro lenguaje. y tengo una variable que maneja el tamaño de la fuente estare usando TTF aun no se que espacion tengo entre caracteres pero podria ser 2px y lo que me gustaria hacer es que esa matrix se le asignaran las columnas y las filas por la cantidad de caracteres especificos dependiendo del tamano de la fuente( se puede omitir el espacio en letras) la verdad ese el problema mas incomodo que he visto me gustaria por favor si es posible unas recomendaciones de ustedes, lo pongo en este foro por que no me gustaria si aparece alguien a limitarme a programadores de c++ o c, lo importante es como se podria implementar el algoritmo, la verdad no tengo nada aun hecho.

Gracias de antemano y disculpen las molestias!!
2  Programación / Programación C/C++ / lista enlazada opiniones [CODIGO FUENTE] en: 14 Febrero 2017, 23:07 pm
un saludo a todos , ahora mismo me encuentro estudiando estructura de datos y estoy tratando de aprender a  crear lista enlazada !!

Código
  1.  
  2.  
  3. class Link{
  4. struct node{
  5. node *next;
  6. int vl;
  7. };
  8.  
  9. node *head;
  10. node *curr;
  11. node *temp;
  12.  
  13. public:
  14.  
  15.  
  16. Link(){
  17. head = curr = temp = NULL;
  18. }
  19.  
  20. void Add(int d){
  21.  
  22. node *n = new node;
  23. n-> next = NULL;
  24. n->vl = d;
  25.  
  26.  
  27.   if( head == NULL)
  28.   {
  29.   head = n;
  30.   }
  31.   else
  32.   {
  33.      curr = head ;
  34.      while(curr->next){
  35.      curr = curr->next;
  36.      }
  37.      curr->next = n;
  38.      curr = n;
  39.   }
  40.  
  41. }
  42.  
  43. void Delete(int vl){
  44. temp = head;
  45. curr = head;
  46. node *temp_;
  47. if(head != NULL){
  48.  
  49. if( head->vl == vl )
  50. {
  51.   if(head->next != NULL)
  52.   {
  53.   temp  = head->next;
  54.  
  55.   temp_ = head;
  56.  
  57.   head = temp;
  58.  
  59.   delete temp_;
  60.   temp_ = NULL;
  61.   return;
  62.   }
  63.  
  64. }
  65. }
  66.  
  67.        while(curr != NULL && curr->vl != vl){
  68.         temp = curr;
  69.         curr = curr->next;
  70.        }
  71. if(curr == NULL)
  72. return;
  73. else{
  74. temp_ = curr;
  75. curr = curr->next;
  76. temp->next = curr;
  77.    delete temp_;
  78.    temp_ = NULL;
  79. }
  80.  
  81.  
  82. }
  83.  
  84.  void Print(){
  85.  node *temp = head;
  86.  if(temp != NULL){
  87.  while(temp != NULL)
  88.  {
  89.  cout << temp->vl <<endl;
  90.  temp = temp->next;
  91.  }
  92.  }
  93.  }
  94.  
  95. };
  96.  
  97.  
  98.  
  99.  
  100. int main(){
  101.  
  102. Link li;
  103. li.Add(0);
  104.    li.Add(1);
  105.    li.Add(2);
  106.    li.Add(3);
  107.    li.Add(4);
  108.    li.Add(5);
  109.    li.Add(6);
  110.    li.Add(7);
  111.    li.Add(8);
  112.    li.Add(9);
  113.    li.Delete(5);
  114.    li.Delete(0);
  115.    li.Delete(8);
  116.    li.Print();
  117.  
  118. }
  119.  
  120.  
  121.  
  122.  
  123.  



 me gustaria opiniones.  gracias de antemano...
3  Programación / Programación C/C++ / array y limite de array sobrepasado... en: 31 Enero 2017, 21:31 pm
Buenas a todos !!
tengo una duda sobre arreglos !!


tengo la siguiente estructura.


Código
  1. struct Tra{
  2.  
  3.   char b[8];
  4.   char c[32];
  5. };
  6.  
  7. ...
  8.  
  9. int main(){
  10.  
  11.   Tra tr;
  12.   memset(&tr, 0x00, sizeof(tr));
  13.  
  14.   strncpy(b, "123456789", 7);
  15.   strncpy(c, "abecdefeghijklmnopqrstuvywz");
  16.  
  17.   cout << b <<endl;
  18.  
  19. }
  20.  
  21.  
Código
  1. salida : >> 123456789abecedefghi.....
  2.  

me gustaria saber por que pasa eso con el valor de b si solo copio una cantidad especifica de caracteres en b?

nota : entiendo que c y c++ no tiene bound check .




el problema no es la compilacion ,esto lo edite rapido :D

pero al parecer no entendieron asi que me explicare , como cree esta estructura Tra
cree dos variable de tipo array a char , ambas con tamanos diferente , luego instancie un objeto de Tra en main , lo limpie ,luego le puse valores no importa que valor estos solo son ejemplo , luego lo imprimi solo el valor de la primera variable y la salida fue la mezcla de todos los valores de la variable c dentro de b , se que las estructura de array plano son como un super array pero por que salen todos los valore de c en b si solo copie cierta cantidad de char con strncpy?
4  Programación / Java / socket, serversocket, interoperacion con otros lenguaje. en: 1 Enero 2017, 21:47 pm
   Buenas a tod@s feliz inicio de año nuevo...
   bien, tengo una duda estoy tratando de crear un aplicacion te tipo webserver/server
   usando socket , serversocket, solamente por que quiero aprender y tambien quisiera saber si
   este servidor puede interactuar con aplicaciones escritas en otros lenguajes (c++, c.. obvio que si)
   quisiera entender por pasos y no soy nuevo en java pero para esta aplicacion mis conocimientos de socket
   son limitados , quisiera entender, quisiera que me recomendaran algun libro y link donde pueda leer
   acerca de este tema.
   
   
   pero como quiera les quiero mostrar algo sencillo , que quizas todos los que saben de      estetema en el foro saben.




Código
  1. package ConexionCliente;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.BufferedOutputStream;
  5. import java.io.BufferedReader;
  6. import java.io.DataInputStream;
  7. import java.io.DataOutputStream;
  8. import java.io.IOException;
  9. import java.io.InputStreamReader;
  10. import java.io.ObjectInputStream;
  11. import java.io.ObjectOutputStream;
  12. import java.io.PrintWriter;
  13. import java.net.Socket;
  14.  
  15. public class SocketCliente{
  16.  
  17. ///BufferedOutputStream bout = null;
  18. ///BufferedInputStream  bin  = null;
  19. ObjectOutputStream output = null;
  20. ObjectInputStream  input  = null;
  21. Socket               sck  = null;
  22. boolean              can  = false;
  23.  
  24.  
  25. public SocketCliente(){
  26. try{
  27. sck = new Socket("localhost", 4444);
  28. }
  29. catch(Exception e)
  30. {
  31.   e.printStackTrace();
  32. }
  33. }
  34.  
  35.  
  36.  
  37.  
  38.  
  39. public SocketCliente(String host, int port){
  40. try
  41. {
  42. sck = new Socket( host , port);
  43.    if(sck != null)
  44.     System.out.println("Se Conecto con "+sck.getInetAddress().getHostAddress() );
  45. }
  46. catch(Exception e)
  47. {
  48.   e.printStackTrace();
  49. }
  50. System.out.println("SocketCliente");
  51. }
  52.  
  53.  
  54. public String receive(){
  55. System.out.println("receive");
  56. String ret= null;
  57.  
  58. if(sck.isClosed())
  59. {
  60.    System.out.print("Socket is Close");
  61.    return ret;
  62. }
  63.  
  64. try {
  65. BufferedReader br = new BufferedReader(new InputStreamReader(sck.getInputStream()));
  66.  
  67. String t;
  68. while((t = input.readLine()) != null){
  69. ret += t;
  70. System.out.println(t);
  71. }
  72. //br.close();
  73. input.close();
  74.  
  75. } catch (IOException e) {
  76. e.printStackTrace();
  77. }
  78. finally{
  79. System.out.println("receive");
  80. return ret;
  81. }
  82. }
  83.  
  84.  
  85. public void Send(String str){
  86.  
  87. System.out.printf("%s\n", str);
  88. try {
  89.  
  90.  
  91. if(sck.isClosed())
  92. {
  93.    System.out.print("Socket is Close");
  94.    return;
  95. }
  96.    PrintWriter pw = new PrintWriter(sck.getOutputStream());
  97.        pw.print(str);
  98.     pw.flush();
  99. //output = new ObjectOutputStream(sck.getOutputStream());
  100. //output.writeBytes(str);
  101.    //output.flush();
  102.    //output.close();
  103. } catch (IOException e) {
  104. // TODO Auto-generated catch block
  105. e.printStackTrace();
  106. }
  107. finally{
  108. System.out.println("Send");
  109. }
  110. }
  111.  
  112. public void Close(){
  113. if(!sck.isClosed())
  114. {
  115.   try {
  116. sck.close();
  117. } catch (IOException e) {
  118. // TODO Auto-generated catch block
  119. e.printStackTrace();
  120. }
  121. }
  122. }
  123.  
  124. }

este codigo es de Main
Código
  1. public class Main {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. //try{
  6. //Socket s = new Socket(InetAddress.getByName("stackoverflow.com"), 80);
  7. //PrintWriter pw = new PrintWriter(s.getOutputStream());
  8.    //pw.print("GET / HTTP/1.1\r\nHost: stackoverflow.com\r\n\r\n");
  9.   /// pw.print("Host: stackoverflow.com\r\n\r\n");
  10. //pw.flush();
  11. //BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
  12. //String t;
  13. //while((t = br.readLine()) != null) System.out.println(t);
  14. //br.close();
  15. //}catch(Exception e){
  16.    // e.printStackTrace();
  17. //}
  18.   String str;
  19.   str = "GET / HTTP/1.1\r\nHost: google.com\r\n\r\n";
  20.  /// SocketCliente sck = new SocketCliente("google.com", 80);
  21.   SocketCliente sck = new SocketCliente("localhost",4444);
  22.   sck.Send(str);
  23.   String res  = sck.receive();
  24.   System.out.println(res);
  25.   sck.Close();
  26.  
  27.  




ahora el codigo del servidor


Código
  1.  
  2. package Server;
  3.  
  4. import java.io.BufferedInputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.InputStreamReader;
  8. import java.io.OutputStreamWriter;
  9. import java.io.Reader;
  10. import java.io.Writer;
  11. import java.net.ServerSocket;
  12. import java.net.Socket;
  13. import java.util.Date;
  14.  
  15. public class Server implements Runnable{
  16.  
  17. int          puerto;
  18. ServerSocket ssock;
  19. Socket        sock;
  20. boolean        isrun = true;
  21. String         server_id;
  22. String         response;
  23.  
  24.  
  25. Server(int puerto, String sid){
  26. this.puerto = puerto;
  27. server_id = sid;
  28.    try{
  29. ssock = new ServerSocket(puerto);
  30.    }catch(IOException e){
  31.     e.printStackTrace();
  32.    }
  33. }
  34.  
  35. public void HandleRequest(){
  36.  
  37. System.out.println("manejando desde el Puerto "+ Integer.toString(puerto));
  38.  
  39.  try{
  40. sock = ssock.accept();
  41. System.out.println("cliente Conectado desde la IP "+sock.getRemoteSocketAddress());
  42.  
  43. Reader in = new InputStreamReader(new BufferedInputStream(sock.getInputStream()));
  44.  
  45. StringBuilder request = new StringBuilder(2048);
  46. while (true) {
  47. int c = in.read();
  48. if (c == '\r' || c == '\n' || c == -1) break;
  49. request.append((char) c);
  50. }
  51.  
  52. System.out.printf("%s", request.toString());
  53.  
  54. Writer out = new OutputStreamWriter(sock.getOutputStream());
  55. Date now = new Date();
  56. out.write(now.toString() +"\r\n");
  57. out.flush();
  58. sock.close();
  59. isrun = false;
  60.        System.out.println("Cliente desconectado");
  61.  
  62.  }catch(IOException e){
  63.  e.printStackTrace();
  64.  }
  65.  
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. @Override
  76. public void run() {
  77. while(isrun){
  78. System.out.println("Esperando conexion....");
  79. HandleRequest();
  80. }
  81.  
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. }
  90.  
  91.  
  92.  



Bueno cada vez que trato de interactuar el servirdor lee solo hasta \n \t el reader no me permite leer una linea completa se queda colgado, me gustaria que me ayudaran por favor post-data la informacion que me respoda no importa esta parte se puede obviar. gracias de antemano por los consejos..



5  Programación / Java / Ejemplo real sobre thread en: 13 Diciembre 2016, 17:31 pm
Buenas a todos de nuevo!!

ahora estoy tratando de enteder los hilos de java , he leido un par de escritos y todos con el mismio esquema de contar numeros hasta 10 y cosas asi ,si es posible alguien me podria mostrar un ejemplo de uso diario de los hilos.  gracias de antemano.
6  Programación / Java / JPanel no dibuja imagen [inherit] en: 9 Diciembre 2016, 14:10 pm
buenas a todos !!


les cuento mi duda estoy tratando de ponerle un background a mi jpanel pasandole una image preeviamente cargada , cuando trato de dibujar con la funcion heredada de PaintComponent la imagen aparece null , es extrano por que todas las imagenes que pongo las uso en otro componente es mas antes de pasarla verifico de varias formas que no sea nulo pero al final es lo mismo siempre, mas abajo esta el codigo de jpanel

Código
  1. public class RockPosPanel  extends JPanel{
  2.  
  3.      Image Icon;
  4.      String url;
  5.  int x, y,w,h;
  6.  
  7.  JLabel label;
  8.  
  9.  
  10.   public RockPosPanel(){
  11.   super(null);
  12.       super.setLayout(null);
  13.   }
  14.  
  15.   public RockPosPanel(String str){
  16.   this();
  17.  
  18.   x = 0;
  19.   y = 0;
  20.   w = 100;
  21.   h = 100;
  22.   url = str;
  23.   if(str != null)
  24.   {
  25.   try {
  26.       System.out.print("Cargando imagen");
  27.   Icon = ImageIO.read(new File(str));
  28.       if(Icon == null)
  29.       System.out.println("La image es null desde que la cargan");
  30.  
  31.   } catch (IOException e) {
  32.  
  33. e.printStackTrace();
  34. }
  35.  
  36.  
  37.  
  38.   }
  39.   }
  40.  
  41.  
  42.  
  43.   public void SetImage(Image im, int x, int y, int w, int h)
  44.   {
  45.  
  46.   if(im != null)
  47.   this.Icon = im;
  48.  
  49.   this.x = x;
  50.   this.y = y;
  51.   this.w = w;
  52.   this.h = h;
  53.   }
  54.  
  55. @Override
  56.  protected void paintComponent(Graphics g) {
  57.    super.paintComponent(g);
  58.  
  59.      if(Icon == null)
  60.      {
  61.      if(url !=null)
  62. try {
  63. Icon = ImageIO.read(new File(url));
  64. } catch (IOException e) {
  65. // TODO Auto-generated catch block
  66. e.printStackTrace();
  67. }
  68.       if(Icon == null)
  69.       System.out.println("La image es null desde que la cargan");      
  70.  
  71.      System.out.println("La image es null");
  72.      }
  73.  
  74.      if(Icoo)
  75.      g.drawImage(Icon,x,y, w, h, this);
  76.  
  77.     ///System.out.println("image is null");
  78.  
  79. }
  80.  
  81. }
  82.  


y cuando pruebo la isntancia de la clase :
Código
  1. Cargando imagen
  2. la imagen no es null
  3. image is null
  4.  
  5. image is null
  6.  
  7. image is null
  8.  
  9. image is null
  10.  
  11. image is null
  12.  
  13. image is null



quizas me falto implementar algo pero la verdad no he encontrado informacion en la red
si alguien me diera una recomendacion, seria mas que suficiente.
 gracias de antemano.
7  Programación / Bases de Datos / insertar en varias tablas fk y pk en: 1 Diciembre 2016, 03:59 am
un saludo a tod@s en el foro!!

soy nuevo en esto de base de datos ,y quiero entender algo, le explico tengo varias tablas , normalizadas y como es entendible hay una relaccion donde una de las columna de la tabla es una llave foranea de otra tabla ,entonces me gustaria ver un ejemplo de como puedo hacer un insert en ambas tablas ejemplo...


 tabla cliente ( idcliente, nombre....)
tabla datoscliente ( idcliente fk, direccion,...)

 esa seria mi tabla de prueba quisiera insertar datos en ambas tablas ,como podria hacerlo??? 
8  Programación / Programación C/C++ / Ayuda, con Opciones de compilacion en: 4 Noviembre 2016, 21:42 pm
Buenas a todos!!

tengo como siempre un par de preguntas :

1- estoy tratando de linkear una libreria estatica (.a) desde una ruta alternativa al path que tiene el compilador por defecto y si siempre me dice que no encuentra la libreria,
estoy usando GCC segun el manual pasando el path con la opcion -LC eso esta resuelto pero no es asi.

2- estoy tratando de utilizar la libreria .a pero sin el prefijo lib, segun varias fuentes en internet pasando -l:<Nombre_de_mi_libreira>.a eso deberia estar resuelta pero no, tambien puede ser que el problema dependa del punto 1.


 quite todas las dependencias de la libreria solamente para probar la aplicacion y este seria le siguiente punto.


3-estoy tratando de hacer una prueba fuera de la maquina que tengo en desarrollo y cuando trato de correr la aplicacion ya creada , me sale un msg que dice, que la version de la aplicacion no es compatible con la version de windows que estoy utilizando, que verifique si necesito una version de 32 o 64 bit de la aplicacion y contacte al que publica la aplicacion.


agradezco por adelantado.

9  Programación / Java / [AYUDA] jdbc , conexion que se queda colgando. en: 21 Octubre 2016, 18:37 pm
un Saludo a Todos !!

tengo un incovenienten , les cuento estoy creado una clase para que me haga de manager con las bases de datos es decir que me cree la conexion , que ejecutes los query o  alguna actulizacion y luego cierre la conexion , el siguiente incoveniente es el que tengo , mi clase se conecta bien a la base de datos (estoy usando Auntenticacion )si fallo me da error y luego si trato ingresar con un usuario valido como quiera me da la misma excepcion(rechanzando la conexion ), estoy usando Derby pero supongo que es problema de programacion, la verdad estoy perdido. dejare el codigo a ver si me pueden hechar una mano o consejo

Código
  1.  
  2. public class RockPosDBManager
  3. {
  4. private boolean debugEnable;
  5. private int     engine;
  6. private int     typeOfConn;
  7.  
  8.  
  9. private String  Embeddeddriver    = "org.apache.derby.jdbc.EmbeddedDriver";
  10. private String  Clientdriver      = "org.apache.derby.jdbc.ClientDriver";
  11. private String  mySQLClientDriver = "com.mysql.jdbc.Driver";
  12.  
  13. private String  DerbyServer   = "jdbc:derby://localhost:1527/";
  14. private String  DerbyNoServer = "jdbc:derby:/";
  15. private String  MySQLServer   = "jdbc:mysql://localhost:3306/";
  16.  
  17.  
  18. private String  DBName;
  19. private String  UserName;
  20. private String  password;
  21.  
  22.  
  23. private String finalConnectionString;
  24. private String finalDriver;
  25. private boolean    Authentication;
  26.  
  27.  
  28. private boolean    create;
  29. private Connection connection;
  30. private boolean    isConnected;
  31.  
  32.  
  33. /**
  34. * @function Print
  35. * @brief  this function Print Information on terminal console if the Debug Flag is enable.
  36. * @param String - this String is the value that will be print onto the screen
  37. * */
  38. private void Print(String templ){
  39. if( debugEnable == false) return;
  40. if( templ != null )
  41. {
  42. //System.out.printf("DEBUG :  %s\n", templ );
  43. }
  44. }
  45.  
  46.  
  47. /**
  48. * @function Print
  49. * @brief  this constructor will set the current Engine, kind of connection, we have  avaliable Derby engine and Mysql .
  50. * @param  int sqlEngine =type of Engine rockPosClient = server, embedded or Client
  51. * @see  RockPosDBEngine &  RockPosTypeConn
  52. * */
  53. public RockPosDBManager(int sqlEngine , int rockposClient, boolean created ){
  54. this.engine     = sqlEngine;
  55.    this.typeOfConn = rockposClient;
  56.    this.debugEnable     = false;
  57.    this.isConnected = false;
  58.    this.create = created;
  59. }
  60.  
  61. /**
  62. * @function setDebugVerbose
  63. * @brief  this function will turn on the Debug Flag for Terminal.
  64. * @param  none
  65. * @see  
  66. * */
  67. public void setDebugVerbose(boolean e){
  68. debugEnable=e;
  69. }
  70.  
  71. /**
  72. * @function isConnectedIntoDatabase
  73. * @brief  this Function Verify if the databe is connected;
  74. * @param  none
  75. * @see  
  76. * */
  77. public boolean isConnectedIntoDatabase(){
  78. return this.isConnected;
  79. }
  80.  
  81. /**
  82. * @function SetDBNameConn
  83. * @brief  
  84. * @param  
  85. * @see  
  86. * */
  87. public void SetDBNameConn(String DBname){
  88.     try{
  89.     if(DBname == null)
  90.     throw new Exception("DB name Is null.");
  91.  
  92.     this.DBName = DBname;
  93.     Print("DB name is : "+ DBName);
  94.  
  95.  
  96.     switch(engine){
  97.  
  98.     case RockPosDBEngine.SQL_DERBY:
  99.      Print("ENGINE SQL_DERBY");
  100.     switch(typeOfConn)
  101.     {
  102.     case RockPosTypeConn.ROCKPOS_CLIENT:
  103.      Print("Type Of Connection  ROCKPOS_CLIENT");
  104.       finalConnectionString = DerbyServer   + this.DBName;
  105.       finalDriver = Clientdriver;
  106.       break;
  107.     case RockPosTypeConn.ROCKPOS_EMBEDDED:
  108.       Print("Type Of Connection  ROCKPOS_EMBEDDED");
  109.       finalConnectionString = DerbyNoServer  + this.DBName;
  110.       finalDriver = Embeddeddriver ;
  111.       break;
  112.     case RockPosTypeConn.ROCKPOS_SERVER:
  113.       Print("Type Of Connection  ROCKPOS_SERVER");
  114.       finalConnectionString = DerbyServer   + this.DBName;
  115.       finalDriver = Clientdriver;
  116.       break;
  117.     }
  118.     break;
  119.  
  120.  
  121.     case RockPosDBEngine.SQL_MYSQL:
  122.     Print("ENGINE SQL_MYSQL");
  123.  
  124.  
  125.     switch(typeOfConn)
  126.     {
  127.     case RockPosTypeConn.ROCKPOS_CLIENT:
  128.     ///   Print("Type Of Connection  ROCKPOS_CLIENT");
  129.       finalConnectionString = MySQLServer   + this.DBName;
  130.       finalDriver = mySQLClientDriver;
  131.       break;
  132.     case RockPosTypeConn.ROCKPOS_EMBEDDED:
  133.     ////  Print("Type Of Connection  ROCKPOS_EMBEDDED");
  134.       Print("MySQL does not work in Embedded Mode yet.");
  135.       finalDriver = mySQLClientDriver;
  136.       break;
  137.     case RockPosTypeConn.ROCKPOS_SERVER:
  138.     ////  Print("Type Of Connection  ROCKPOS_SERVER");
  139.       finalConnectionString = MySQLServer  + this.DBName;
  140.       finalDriver = mySQLClientDriver;
  141.       break;
  142.     }
  143.     break;
  144.     }
  145.      Print("Connection Driver is : "+ finalDriver);
  146.      Print("Connection String is  ===> "+ finalConnectionString);
  147.     if(this.UserName != null && this.password != null)
  148.     {
  149.     Print("Authentication is  On.");
  150.     Print("User name is =[ "+this.UserName+ " ] password = [ "+ this.password +"]");
  151.     Authentication = true;
  152.     }
  153.     else
  154.     {
  155.      Print("Authentication is  On.");
  156.      Print("No user name was provide.");
  157.     Authentication = false;
  158.  
  159.     }
  160.  
  161.     }catch(Exception e)
  162.     {
  163.      e.printStackTrace();
  164.     }
  165. }
  166.  
  167. /**
  168. * @function SetCredential
  169. * @brief  
  170. * @param  
  171. * @see  
  172. * */
  173. public void SetCredential(String user, String pass){
  174.   if(user != null)
  175.   this.UserName = user;
  176.   if(pass != null)
  177.     this.password = pass;
  178. }
  179.  
  180. public void RequireAuth(boolean auth){
  181. this.Authentication = auth;
  182. }
  183.  
  184.  
  185.  
  186. /**
  187. * @function Connect
  188. * @brief  
  189. * @param  
  190. * @see  
  191. * */
  192. public boolean Connect(){
  193.  
  194. this.connection = null;
  195. try{
  196. Class.forName(finalDriver);
  197. }
  198. catch(Exception e)
  199. {
  200. e.printStackTrace();
  201.  
  202. this.isConnected = false;
  203. return this.isConnected ;
  204. }
  205.  
  206. try{
  207.  
  208. String param;
  209.   if(create == false)
  210.   {
  211.  
  212.   param =  finalConnectionString +";user="+ this.UserName+";password="+ this.password;
  213.  
  214.   }
  215.   else
  216.   {
  217.   param =  finalConnectionString +";create=true;user="+this.UserName+";password="+ this.password;
  218.  
  219.   }
  220.  
  221.    System.out.printf("Param to Server : %s", param);
  222.    this.connection = DriverManager.getConnection(param);
  223.                    if(this.connection.isValid(30)){
  224.                     this.isConnected = true;
  225.                     System.out.print("\nEsta Conectado.");
  226.                    }
  227.                    else{
  228.                     this.isConnected = false;
  229.                     System.out.print("\nno Esta Conectado.");
  230.  
  231.                    }
  232.  
  233.  
  234. }
  235. catch(SQLException e)
  236. {
  237.   int code = e.getErrorCode();
  238.   e.printStackTrace();
  239.   this.isConnected = false;
  240.   return this.isConnected;
  241. }
  242.  
  243.  
  244.      return this.isConnected;
  245.  
  246. }
  247.  
  248.  
  249. public boolean Disconnect(){
  250.  
  251.   try {
  252.     this.connection.close();
  253.     } catch (SQLException e) {
  254.  
  255.      e.printStackTrace();
  256.  return isConnected;
  257.     }
  258.     this.isConnected = false;
  259. return isConnected;  
  260. }
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. public boolean Execute(String sql){
  271. ///Print("Execute");
  272. boolean res = true;
  273. if(this.isConnected == false  )
  274. {
  275.   Print("theres is not Connection");
  276.   return false;
  277. }
  278.  
  279. PreparedStatement stmt   = null;
  280. try
  281. {
  282.    stmt   =  this.connection.prepareStatement(sql);
  283.    stmt.executeUpdate(sql);
  284. }catch(Exception e){
  285. e.printStackTrace();
  286. Print("Error Executing that Query");
  287. return false;
  288. }
  289. finally{
  290. ///Print("Execute Finally");
  291. try {
  292. stmt.close();
  293.  
  294. } catch (Exception e) {
  295.        Print("Error closing Statement.");
  296. }
  297. }
  298. return res;
  299. }
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308. public ResultSet Query(String sql){
  309.  
  310. if(this.isConnected == false  )
  311. {
  312.   Print("theres is not Connection");
  313.   return null;
  314. }
  315.  
  316. Statement stmt   = null;
  317. ResultSet result = null;
  318. try
  319. {
  320.  
  321.  
  322. this.connection.setAutoCommit(true);
  323.    stmt   =  this.connection.createStatement();
  324.    result = stmt.executeQuery(sql);
  325.    if(result == null)
  326.     Print("Result is null");
  327.  
  328. }catch(Exception e){
  329. Print("Error Executing that Query");
  330. }
  331. try {
  332. stmt.close();
  333. } catch (Exception e) {
  334.            Print("Error closing Statement.");
  335. }
  336. return result;
  337. }
  338.  
  339.  
  340. public void CloseConn(){
  341. try {
  342. this.connection.close();  
  343. Print("Closing Connection");
  344.  
  345. } catch (Exception e) {
  346.          Print("Error Closing Conection.");
  347. }
  348. this.isConnected= false;
  349.  
  350. }
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357. }
  358.  


algo que me falto ponerle es una prueba de lo que quiero hacer
Código
  1. RockPosDBManager rm = new RockPosDBManager(RockPosDBEngine.SQL_DERBY, RockPosTypeConn.ROCKPOS_CLIENT, true);
  2. rm.SetDBNameConn(RockPosConstant.DB_PATH+"d1234f");
  3. rm.SetCredential("dbmanager", "dbmanager");
  4. boolean creado = rm.Connect();
  5. if(creado == true)
  6. System.out.println("prueba 1Creado");
  7. else{
  8. System.out.println("prueba 1 no Creado");
  9.  
  10. }
  11. String sql = "CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(\'derby.database.defaultConnectionMode\',\'noAccess\')";
  12. creado = rm.Execute(sql);
  13. if(creado == true)
  14. System.out.println(" prueba 2 Se Ejecuto");
  15. else{
  16. System.out.println(" prueba 2 no sejecuto Creado");
  17.  
  18. }
  19.  
  20. rm.Disconnect();
  21. rm.SetDBNameConn(RockPosConstant.DB_PATH+"d1234f");
  22. rm.SetCredential("usuario2", "usuario2");
  23.    creado = rm.Connect();
  24. if(creado == true)
  25. System.out.println("\n\n\n prueba 2 Creado\n");
  26. else{
  27. System.out.println("\n\n\n prueba 2 no Creado\n");
  28.  
  29. }
  30. rm.Disconnect();
  31. rm.SetCredential("dbmanager", "dbmanager");
  32.    creado = rm.Connect();
  33. if(creado == true)
  34. System.out.println(" prueba 4 prueba pasada ");
  35. else{
  36. System.out.println("prueba 4 prueba no pasada");
  37.    return;
  38. }
  39.  
  40.  
  41.  
  42.  
10  Programación / Programación C/C++ / [ayuda] punteros en linklist en: 14 Octubre 2016, 20:53 pm
Buenas a todos !!

estoy actualmete aprendiendo a implementar una lista enlazada simple y me gustaria saber como es que los punteros estan trabajando de manerar interna para poder comunicarse, si es algo sencillo en teoria pero tengo una duda que ronda en mi cabeza hace un par de minutos, estoy siguiendo un tutorial y he entendido algunas cosas como que cada nodo (usando una estructura ) tieene un puntero a otro nodo que esta en una "lista" y al final de la lista hay uno que apunta a NULL y para este aproach estoy usando c++ y plantillas , le explico un poco como tengo mi codigo:

tengo una clase llamada List esta contiene una estructura Node que contiene el dato T y el link al sugiente elemento de la estructura .... ahora en la clase tengo 2 puntero first y curr
estos contienen el dato de la cabeza (Inicio de la estructura) y curr que contiene el frente de la estructura (front )  bien en la funcion siguiente

 
Código
  1.  
  2.    void insert(T f)
  3.    {
  4.      Node<T> *temp= new Node<T>(f);
  5.       if(first == NULL)
  6.       {
  7.       first= temp;
  8.       curr = temp;
  9.       }
  10.       else
  11.       {
  12.       curr->next=temp;
  13.       curr = temp;
  14.       }
  15.    }
  16.  
el primer if esta bien  pero esta parte en else me hace perderme por ejemeplo
Código
  1.     void Print(){
  2.     if(first == NULL) return;
  3.         curr = first;
  4.     while( curr  )
  5.     {
  6.     cout << "Value is : "<< curr->date<<endl;
  7.     curr = curr->next;
  8.     }
  9.     }
  10.  

donde curr = first
toma el first pero en la funcion Insert la que se lleno fue curr por que first tiene el link de first, alguien podria explicarme eso por favor.


Código
  1. #include <iostream>
  2.  
  3. #include <string.h>
  4. using std::cout;
  5. using std::string;
  6.  
  7. template<typename T>
  8. class List
  9. {
  10. private:
  11. template<class R>
  12. struct Node{
  13. R  date;
  14. Node *next;
  15.    Node(T t){
  16.     date = t;
  17.     next = NULL;
  18.    }
  19. };
  20.  
  21. Node<T> *first;
  22. Node<T> *curr;
  23.  
  24. public:
  25.  
  26. List(){
  27. first = NULL;
  28. curr  = NULL;
  29. }
  30.    List(int d)
  31.    {
  32.     Node<T> *temp= new Node<T>(d);
  33.     first = temp;
  34.     curr  = temp;
  35.    }
  36.  
  37.    void insert(T f)
  38.    {
  39.      Node<T> *temp= new Node<T>(f);
  40.       if(first == NULL)
  41.       {
  42.       first= temp;
  43.       curr = temp;
  44.       }
  45.       else
  46.       {
  47.       curr->next=temp;
  48.       curr = temp;
  49.       }
  50.    }
  51.  
  52.     void Print(){
  53.     if(first == NULL) return;
  54.         curr = first;
  55.     while( curr  )
  56.     {
  57.     cout << "Value is : "<< curr->date<<endl;
  58.     curr = curr->next;
  59.     }
  60.     }
  61.  
  62.  
  63.     void DeleteData(int data)
  64.     {
  65.         Node<T> *delPtr = NULL;
  66.         Node<T> *temp   = first;
  67.         curr            = first;
  68.  
  69.         while(curr != NULL && curr->date != data)
  70.         {
  71.         temp = curr;
  72.         curr = curr->next;
  73.         }
  74.  
  75.         if(curr == NULL)
  76.         {
  77.         cout << "this data is not in the list;";
  78.         }
  79.         else
  80.         {
  81.         delPtr = curr;
  82.         curr = curr->next;
  83.          temp->next = curr;
  84.         if(delPtr == first)
  85.         {
  86.         first = first->next;
  87.          temp  = NULL;
  88.         }
  89.             delete delPtr;
  90.         }
  91.  
  92.     }
  93.  
  94.  
  95.  
  96.  
  97. };
  98.  
  99.  
  100.  
  101. int main()
  102. {
  103.   List<int > ls;
  104.   ls.insert(12);
  105.   ls.insert(345);
  106.   ls.insert(345);
  107.   ls.DeleteData(345);
  108.   ls.Print();
  109. }
  110.  
  111.  
Páginas: [1] 2 3 4 5 6 7 8 9
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines