3 Replies Latest reply: Jul 23, 2010 11:16 AM by 783403 RSS

    Scholar92 - Strange error Need help please

    843810
      Lecori Salutem

      The program I have a problem with is supposed to extract info from a DB. It extracts the info perfectly but I cannot access the info with my get commands from other classes.
      When i fire the program it says " [Ljava.lang.String;@1ba34f2 ". Can anyone help me to solve this problem please.

      ////////CODE STARTS HERE

      import java.sql.;
      import javax.swing.;

      / Description:
      Die program word gebruik om al die metadata en paths wat getabuleer is
      op die Music DB te access en te stoor.

      @author Benni( a3aanbotha@gmail.com)
      /

      public class SQLImport
      {

      private Connection connSQL;

      int tel = 2; // ID in SQL tabel begin by "2"
      String [] tName = new String [100];
      String [] tArtist = new String [100];
      String [] tGenre = new String [100];
      String [] tMood = new String [100];
      String [] tPath = new String [100];
      String [] tJavaPath = new String [100];
      String [] tID = new String [100];
      String [] tTime = new String [100];


      public SQLImport( )
      {

      try
      {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      connSQL = DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (.mdb)};DBQ=Music.mdb");
      JOptionPane.showMessageDialog(null, "Connection Successfully Established", "Notification",JOptionPane.INFORMATION_MESSAGE);

      }

      catch (Exception sqlConnectionFailed)
      {
      JOptionPane.showMessageDialog(null, sqlConnectionFailed, "ERROR:",JOptionPane.ERROR_MESSAGE);
      }

      Statement statement = null;
      try
      {
      statement = connSQL.createStatement( );

      }
      catch (SQLException statementERROR)
      {
      JOptionPane.showMessageDialog(null,statementERROR, "ERROR:",JOptionPane.ERROR_MESSAGE);
      }

      char optionChoice;

      do
      {
      optionChoice = getMenuChoice();

      if(optionChoice == 'A')
      {
      try
      {
      String querySQL = "SELECT * FROM tbl_ListedMusic ORDER BY ID ;";
      System.out.println(querySQL);
      ResultSet resultSet = statement.executeQuery(querySQL);

      while (resultSet.next( ))
      {
      tID[tel] = resultSet.getString("ID");
      tName[tel] = resultSet.getString("TrackName");
      tArtist[tel] = resultSet.getString("TrackArtist");
      tTime[tel] = resultSet.getString("TrackTime");
      tGenre[tel] = resultSet.getString("TrackGenre");
      tMood[tel] = resultSet.getString("TrackMood");
      tJavaPath[tel] = resultSet.getString("TrackJavaPath");
      tPath[tel] = resultSet.getString("TrackPath");
      tel++;
      }

      }
      catch (SQLException infoImportError)
      {
      JOptionPane.showMessageDialog(null,infoImportError, "ERROR:",JOptionPane.ERROR_MESSAGE);
      }

      }

      }

      while (optionChoice != 'X');
      {
      //NB! Strings are " " chars are ' '

      }
      }

      public String[ ] gettID( )
      {
      return tID;
      }

      public String[ ] gettName( )
      {
      return tName;
      }


      public char getMenuChoice( )
      {
      String menu = "A) Import .mp3 info \n X) Exit";

      char choice = JOptionPane.showInputDialog(menu).toUpperCase( ).charAt(0);
      return choice;
      }

      public static void main (String [ ] args)
      {
      SQLImport sql = new SQLImport( );
      String [ ] blah = new String [10];
      blah = sql.gettID();
      System.out.println(blah);


      }
      //Code ENDS

      How do I resolve the " [Ljava.lang.String;@1ba34f2 " ? Much apreciated

      Regards,
      Benni                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
        • 1. Re: Scholar92 - Strange error Need help please
          843810
          Your app works fine, everything is ok. In the main method You get an array and display it - not the elements of it but itsefl only. You can do a simple test:
          String [] test = new String[4];
          System.out.println(test);
          The result will be the same. What You want to achieve?
          • 2. Re: Scholar92 - Strange error Need help please
            843810
            I want to use the info that I get from the DB to write .m3u playlists with another class. I couldn't access my test get methods so I tried to test the get methods in the SQLImport itself and then instead of printing the resaults I got that funny message. Once I can just display the info that I've extracted I know that it works and then il try to employ the get methods in my class Playlist.

            I don't fully understand why my results cannot be displayed? Sorry I've only been programming for about 11 months still a newbie.
            • 3. Re: Scholar92 - Strange error Need help please
              783403
              You just need to traverse through your id array and print individual content instead of printing array. using an array reference in System.out.println will always print the memory representation of reference not the contents. So you should do somethind like this.
               
              for(int i=0; i<blah.length; i++) {
              System.out.println(blah);
              }
              Hope this helps.