4 Replies Latest reply: Dec 16, 2008 4:02 PM by 807589 RSS

    Need Help with SQL in Java -- Newbie :-)

    807589
      Greetings:

      I am very new to Java and I am about to embark on a major project which I am sure will cut my teeth on this language. I have been exploring the jdbc connector/j for mysql and I am currently just writing a .class file to query my database to exercise my understanding of this. The query I need to code is as follows:
      SELECT * FROM `artists` 
                     JOIN `albums` ON artists.Artist_ID = albums.Artist_ID 
                     JOIN `statusdef` ON status = statusdef.code 
                     JOIN `mediadef` ON medium = mediadef.code 
                     WHERE Status = 0 ORDER BY artists.ArtistName, albums.AlbumName
      I tried putting this as it is inside of the
      ResultSet rs = stmt.executeQuery
      tag. Of course the javac compiler gave me errors (unclosed string literal). I assume there is a way I need to format this query for Java and this is where I am lost.

      Help would be VERY MUCH APPRECIATED!!!!

      The way the statement looks right now is:
      ResultSet rs = stmt.executeQuery("SELECT * FROM `artists` 
                     JOIN `albums` ON artists.Artist_ID = albums.Artist_ID 
                     JOIN `statusdef` ON status = statusdef.code 
                     JOIN `mediadef` ON medium = mediadef.code 
                     WHERE Status = 0 ORDER BY artists.ArtistName, albums.AlbumName");
      Thanks in advance for your help!