10 Replies Latest reply: Jun 22, 2011 9:32 AM by 863138 RSS

    problem loading images from a return value of a function

    863138
      hello, I write because I uin problem in loading images from a return value of a function.
      I created a database with a field "image" of type string, where I put the physical address of the image. I have written like this: {__DIR__ }foto.jpg
      Place the code, so you understand better

      function imageViewImage(): javafx.scene.image.Image {
      connetti();
      lass.forName(driverName);
      con = DriverManager.getConnection(url,user,"");
      stmt = con.createStatement();
      var richiesta:String = "SELECT image from viaggio WHERE id_viaggio=7";
      rs1 = stmt.executeQuery(richiesta);
      var result :String;
      rs1.next();
      risultato = rs1.getString("image");

      JOptionPane.showMessageDialog(null, result);
      var imagez = Image{
      url:"{result}";
      }
      return imagez;


      The image is in the source code package
      First I connect to the database, run the query and I take the contents of the image.
      Can anyone help me?
      Is right to put in the database {__DIR__} foto.jpg or do I put only foto.jpg?
        • 1. Re: problem loading images from a return value of a function
          Darryl Burke
          Moderator advice: Please read the announcements at the top of the forum listing and the forums FAQ linked from every page. They are there for a purpose.

          Then edit your post and format the code correctly.

          db
          • 2. Re: problem loading images from a return value of a function
            Narayan
            Hello unkus_nob,

            Please format your code properly : http://forums.oracle.com/forums/ann.jspa?annID=1429
            Make forums helpers to help easier for you.

            Thanks.
            Narayan
            • 3. Re: problem loading images from a return value of a function
              863138
              yes, excuse me, I'm new!
              function imageViewImage(): javafx.scene.image.Image {
                   connetti();    //database connection
                   Class.forName(driverName);
                   con = DriverManager.getConnection(url,user,"");
                   stmt = con.createStatement();
                   var richiesta:String = "SELECT image from viaggio WHERE id=7";
                   rs1 = stmt.executeQuery(richiesta);
                   var result :String;
                   rs1.next();
                   risultato = rs1.getString("image");
              
                   var imagez = Image{
                                          url:"{result}";
                            }
                    return imagez; }
              • 4. Re: problem loading images from a return value of a function
                Narayan
                Hello unkus_nob,
                I see some mistake on your program
                 risultato = rs1.getString("image");
                 
                     var imagez = Image{
                                            url:"{result}";
                              }
                why you are using the result as the url source. You can use 'risultato' as source of image url .

                Also, please first use println() function to see if the return value of result is going right.

                --Narayan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
                • 5. Re: problem loading images from a return value of a function
                  863138
                  yes excuse me, i have:
                  risultato = rs1.getString("immagine");
                    
                         JOptionPane.showMessageDialog(null, risultato);
                         var image = Image{
                           url:"{risultato}";
                  
                         }
                         return image;
                  Th JOption pane print: {__DIR__}foto.jpg ,that is the same of the database field, but the code don't run.
                  Is right write in the database field {__DIR__}foto.jpg or is right only foto.jpg?
                  • 6. Re: problem loading images from a return value of a function
                    Narayan
                    Hello unkus_nob,

                    I would rather suggest you to save only filename of that image like "foto.jpg" in database. And just concat it with the String variable containing "{__DIR__}".
                    Actually the javafx compiler converts the {__DIR__} to the existing class directory path something like : "jar:file:/..../".

                    var currentDir ="{__DIR__}";
                    
                    risultato = "{currentDir}{rs1.getString("immagine"})";  
                    
                    var image = Image{
                        url:risultato
                    }
                     
                    return image;
                    --NARAYAN G.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
                    • 7. Re: problem loading images from a return value of a function
                      Darryl Burke
                      Narayan, is the conversion done by the compiler or the runtime? When compiling, the class isn't in a jar.

                      db
                      • 8. Re: problem loading images from a return value of a function
                        Narayan
                        Sorry! DB it's actually the runtime; my mistake.

                        -Narayan GM.
                        • 9. Re: problem loading images from a return value of a function
                          863138
                          I try to putting your solution, in the database field only foto.jpg and then concatenating with currentDir, and the JOptionPane print
                          jar:file:/C:/Users/-----/{__DIR__}foto.jpg
                          but the picture does not appear
                          • 10. Re: problem loading images from a return value of a function
                            863138
                            wait wait, now it works!
                            thanks for availability and for helping me solve the problem!
                            Stefania